Check-in [730308bffd]
Overview
Comment:Added filename and line numbers to error messages. Began adding support for lists of options rather than just one option per item. libconfig 0.1.19
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | 0.1.19
Files: files | file ages | folders
SHA1: 730308bffd7be6879a2c9c32d1eb7ee867f0c7ef
User & Date: rkeene on 2005-09-30 08:27:32
Other Links: manifest | tags
Context
2005-10-18
16:00
Added missing error line/file information for conf_apache libconfig 0.1.20 check-in: b9a32192b7 user: rkeene tags: trunk, 0.1.20
2005-09-30
08:27
Added filename and line numbers to error messages. Began adding support for lists of options rather than just one option per item. libconfig 0.1.19 check-in: 730308bffd user: rkeene tags: trunk, 0.1.19
2005-07-18
11:54
Updated configure process on Win32 to use DLL base. Fixed "lc_cleanup" causing segfaults. check-in: 793852910f user: rkeene tags: trunk, 0.1.18
Changes

Modified Makefile.in from [e7001c02f6] to [53b907f18c].

    13     13   SHOBJFLAGS = @SHOBJFLAGS@
    14     14   SHOBJLDFLAGS = @SHOBJLDFLAGS@
    15     15   SHOBJEXT = @SHOBJEXT@
    16     16   ARFLAGS = # @ARFLAGS@
    17     17   AREXT = @AREXT@
    18     18   PKGVERS = @PACKAGE_VERSION@
    19     19   PKGVERSMAJOR = `echo $(PKGVERS) | cut -f 1 -d .`
           20  +EXEEXT = @EXEEXT@
    20     21   
    21     22   prefix = @prefix@
    22     23   mandir = @mandir@
    23     24   sysconfdir = @sysconfdir@
    24     25   datadir = @datadir@
    25     26   exec_prefix = @exec_prefix@
    26     27   bindir = @bindir@

Modified build/h-to-hin from [e6b4d57000] to [34a6b6eb8a].

     1      1   #! /bin/sh
     2      2   
     3      3   if [ libconfig.h -nt libconfig.h.in ]; then
     4      4   	echo 'Updating libconfig.h.in ...'
     5         -	sed 's@^#  @!@;s@^ *$@|__BLANK_LINE__|@' libconfig.h | tr '|' "\n" > libconfig.h.in
            5  +	sed 's@^#  @!@;s@^ *$@:__BLANK_LINE__:@' libconfig.h | tr ':' "\n" > libconfig.h.in
     6      6   else
     7      7   	echo 'Updating libconfig.h ...'
     8      8   	make libconfig.h
     9      9   fi

Added build/test.conf version [9a98f498a7].

            1  +
            2  +
            3  +<section>
            4  +	test Bob was here
            5  +</section>
            6  +
            7  +<somesection>
            8  +	Free yes, no
            9  +</somesection>
           10  +
           11  +#<joe>
           12  +#</joe>
           13  +
           14  +sally 3

Modified compat.h from [e7ac67c392] to [b6a11fd72e].

    84     84   #endif
    85     85   
    86     86   #ifdef HAVE_OPENNET_H
    87     87   #include <opennet.h>
    88     88   #endif
    89     89   #ifdef HAVE_LIBOPENNET
    90     90   #define lc_fopen(path, mode) fopen_net(path, mode)
           91  +#define lc_fgets(buf, size, stream) fgets_net(buf, size, stream)
           92  +#define lc_feof(stream) feof_net(stream)
           93  +#define lc_fclose(stream) fclose_net(stream)
           94  +#define LC_FILE NETFILE
    91     95   #else
    92     96   #define lc_fopen(path, mode) fopen(path, mode)
           97  +#define lc_fgets(buf, size, stream) fgets(buf, size, stream)
           98  +#define lc_feof(stream) feof(stream)
           99  +#define lc_fclose(stream) fclose(stream)
          100  +#define LC_FILE FILE
    93    101   #endif
    94    102   
    95    103   #endif

Modified conf_apache.c from [cd77d73d2e] to [dfc17c3008].

    77     77   		}
    78     78   	}
    79     79   
    80     80   	return(retval);
    81     81   }
    82     82   
    83     83   static int lc_process_conf_apache_file(const char *configfile, const char *pathprefix) {
    84         -	FILE *configfp = NULL;
           84  +	LC_FILE *configfp = NULL;
           85  +	const char *local_lc_errfile;
    85     86   	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL, *tmp_ptr = NULL;
    86     87   	char *lastsection = NULL;
    87     88   	char qualifbuf[LC_LINEBUF_LEN] = {0};
    88     89   	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
    89     90   	char *fgetsret = NULL;
    90     91   	int lcpvret = -1, lpcafret = -1;
    91     92   	int invalid_section = 0, ignore_section = 0;
           93  +	int local_lc_errline;
    92     94   	int retval = 0;
    93     95   	lc_err_t save_lc_errno = LC_ERR_NONE;
    94     96   
    95     97   	if (pathprefix != NULL) {
    96     98   		/* Copy the prefix, if specified. */
    97     99   		strncpy(qualifbuf, pathprefix, sizeof(qualifbuf) - 1);
    98    100   	}
          101  +
          102  +	local_lc_errfile = configfile;
          103  +	local_lc_errline = 0;
    99    104   
   100    105   	if (configfile == NULL) {
          106  +		lc_errfile = local_lc_errfile;
          107  +		lc_errline = local_lc_errline;
   101    108   		lc_errno = LC_ERR_INVDATA;
   102    109   		return(-1);
   103    110   	}
   104    111   
   105    112   	configfp = lc_fopen(configfile, "r");
   106    113   
   107    114   	if (configfp == NULL) {
          115  +		lc_errfile = local_lc_errfile;
          116  +		lc_errline = local_lc_errline;
   108    117   		lc_errno = LC_ERR_CANTOPEN;
   109    118   		return(-1);
   110    119   	}
   111    120   
   112    121   	while (1) {
   113         -		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
          122  +		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
   114    123   		if (fgetsret == NULL) {
   115    124   			break;
   116    125   		}
   117         -		if (feof(configfp)) {
          126  +		if (lc_feof(configfp)) {
   118    127   			break;
   119    128   		}
          129  +
          130  +		local_lc_errline++;
   120    131   
   121    132   		/* Remove trailing crap (but not spaces). */
   122    133   		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
   123    134   		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
   124    135   			*linebuf_ptr = '\0';
   125    136   			linebuf_ptr--;
   126    137   		}
................................................................................
   160    171   
   161    172   				if (strcmp(cmd, lastsection) != 0) {
   162    173   #ifdef DEBUG
   163    174   					fprintf(stderr, "Section closing does not match last opened section.\n");
   164    175   					fprintf(stderr, "Last opened = \"%s\", Closing = \"%s\"\n", lastsection, cmd);
   165    176   #endif
   166    177   					retval = -1;
          178  +					lc_errfile = local_lc_errfile;
          179  +					lc_errline = local_lc_errline;
   167    180   					lc_errno = LC_ERR_BADFORMAT;
   168    181   
   169    182   					/* For this error, we abort immediately. */
   170    183   					break;
   171    184   				}
   172    185   
   173    186   				lcpvret = lc_process_var(qualifbuf, NULL, NULL, LC_FLAGS_SECTIONEND);
................................................................................
   228    241   
   229    242   			lcpvret = lc_process_var(qualifbuf, value, NULL, LC_FLAGS_SECTIONSTART);
   230    243   			if (lcpvret < 0) {
   231    244   #ifdef DEBUG
   232    245   				fprintf(stderr, "Invalid section: \"%s\"\n", qualifbuf);
   233    246   #endif
   234    247   				invalid_section = 1;
          248  +				lc_errfile = local_lc_errfile;
          249  +				lc_errline = local_lc_errline;
   235    250   				lc_errno = LC_ERR_INVSECTION;
   236    251   				retval = -1;
   237    252   			}
   238    253   			if (lcpvret == LC_CBRET_IGNORESECTION) {
   239    254   				ignore_section = 1;
   240    255   			}
   241    256   			continue;
................................................................................
   284    299   		}
   285    300   
   286    301   		cmd = linebuf_ptr;
   287    302   
   288    303   		/* Handle special commands. */
   289    304   		if (strcasecmp(cmd, "include") == 0) {
   290    305   			if (value == NULL) {
          306  +				lc_errfile = local_lc_errfile;
          307  +				lc_errline = local_lc_errline;
   291    308   				lc_errno = LC_ERR_BADFORMAT;
   292    309   				retval = -1;
   293    310   #ifdef DEBUG
   294    311   				fprintf(stderr, "Invalid include command.\n");
   295    312   #endif
   296    313   				continue;
   297    314   			}
................................................................................
   323    340   #endif
   324    341   				lc_errno = LC_ERR_INVCMD;
   325    342   			} else {
   326    343   #ifdef DEBUG
   327    344   				fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
   328    345   #endif
   329    346   			}
          347  +			lc_errfile = local_lc_errfile;
          348  +			lc_errline = local_lc_errline;
   330    349   			retval = -1;
   331    350   		} else {
   332    351   			lc_errno = save_lc_errno;
   333    352   		}
   334    353   
   335    354   		/* Remove the "cmd" part of the buffer. */
   336    355   		tmp_ptr = strrchr(qualifbuf, '.');
   337    356   		if (tmp_ptr == NULL) {
   338    357   			tmp_ptr = qualifbuf;
   339    358   		}
   340    359   		*tmp_ptr = '\0';
   341    360   	}
   342    361   
   343         -	fclose(configfp);
          362  +	lc_fclose(configfp);
   344    363   
   345    364   	return(retval);
   346    365   }
   347    366   
   348    367   int lc_process_conf_apache(const char *appname, const char *configfile) {
   349    368   	return(lc_process_conf_apache_file(configfile, NULL));
   350    369   }

Modified conf_section.c from [f6fa72ff6b] to [291ca9d7b9].

     8      8   #endif
     9      9   
    10     10   #ifdef HAVE_STRING_H
    11     11   #include <string.h>
    12     12   #endif
    13     13   
    14     14   int lc_process_conf_section(const char *appname, const char *configfile) {
    15         -	FILE *configfp = NULL;
           15  +	LC_FILE *configfp = NULL;
           16  +	const char *local_lc_errfile;
    16     17   	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
    17     18   	char qualifbuf[LC_LINEBUF_LEN] = {0};
    18     19   	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
    19     20   	char *currsection = NULL;
    20     21   	char *fgetsret = NULL;
    21     22   	int lcpvret = -1;
    22     23   	int invalid_section = 1, ignore_section = 0;
           24  +	int local_lc_errline;
    23     25   	int retval = 0;
    24     26   	lc_err_t save_lc_errno = LC_ERR_NONE;
           27  +
           28  +	local_lc_errfile = configfile;
           29  +	local_lc_errline = 0;
    25     30   
    26     31   	if (appname == NULL || configfile == NULL) {
           32  +		lc_errfile = local_lc_errfile;
           33  +		lc_errline = local_lc_errline;
    27     34   		lc_errno = LC_ERR_INVDATA;
    28     35   		return(-1);
    29     36   	}
    30     37   
    31     38   	configfp = lc_fopen(configfile, "r");
    32     39   
    33     40   	if (configfp == NULL) {
           41  +		lc_errfile = local_lc_errfile;
           42  +		lc_errline = local_lc_errline;
    34     43   		lc_errno = LC_ERR_CANTOPEN;
    35     44   		return(-1);
    36     45   	}
    37     46   
    38     47   	while (1) {
    39         -		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
           48  +		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
    40     49   		if (fgetsret == NULL) {
    41     50   			break;
    42     51   		}
    43         -		if (feof(configfp)) {
           52  +		if (lc_feof(configfp)) {
    44     53   			break;
    45     54   		}
           55  +
           56  +		local_lc_errline++;
    46     57   
    47     58   		/* Remove trailing crap (but not spaces). */
    48     59   		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
    49     60   		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
    50     61   			*linebuf_ptr = '\0';
    51     62   			linebuf_ptr--;
    52     63   		}
................................................................................
    71     82   			currsection = strdup(linebuf_ptr);
    72     83   			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
    73     84   			if (lcpvret < 0) {
    74     85   #ifdef DEBUG
    75     86   				fprintf(stderr, "Invalid section: \"%s\"\n", currsection);
    76     87   #endif
    77     88   				invalid_section = 1;
           89  +				lc_errfile = local_lc_errfile;
           90  +				lc_errline = local_lc_errline;
    78     91   				lc_errno = LC_ERR_INVSECTION;
    79     92   				retval = -1;
    80     93   			} else {
    81     94   				invalid_section = 0;
    82     95   				ignore_section = 0;
    83     96   			}
    84     97   
................................................................................
   159    172   #endif
   160    173   				lc_errno = LC_ERR_INVCMD;
   161    174   			} else {
   162    175   #ifdef DEBUG
   163    176   				fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
   164    177   #endif
   165    178   			}
          179  +			lc_errfile = local_lc_errfile;
          180  +			lc_errline = local_lc_errline;
   166    181   			retval = -1;
   167    182   		} else {
   168    183   			lc_errno = save_lc_errno;
   169    184   		}
   170    185   	}
   171    186   
   172    187   	/* Close any open section, and clean-up. */
................................................................................
   176    191   #ifdef DEBUG
   177    192   			fprintf(stderr, "Invalid section terminating: \"%s\"\n", currsection);
   178    193   #endif
   179    194   		}
   180    195   		free(currsection);
   181    196   	}
   182    197   
   183         -	fclose(configfp);
          198  +	lc_fclose(configfp);
   184    199   
   185    200   	return(retval);
   186    201   }

Modified conf_space.c from [22b1310a4a] to [0072873b48].

     8      8   #endif
     9      9   
    10     10   #ifdef HAVE_STRING_H
    11     11   #include <string.h>
    12     12   #endif
    13     13   
    14     14   int lc_process_conf_space(const char *appname, const char *configfile) {
    15         -	FILE *configfp = NULL;
           15  +	LC_FILE *configfp = NULL;
           16  +	const char *local_lc_errfile;
    16     17   	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
    17     18   	char *cmd = NULL, *value = NULL, *sep = NULL;
    18     19   	char *fgetsret = NULL;
           20  +	int local_lc_errline;
    19     21   	int lcpvret = -1;
    20     22   	int retval = 0;
    21     23   	lc_err_t save_lc_errno = LC_ERR_NONE;
           24  +
           25  +	local_lc_errfile = configfile;
           26  +	local_lc_errline = 0;
    22     27   
    23     28   	if (appname == NULL || configfile == NULL) {
           29  +		lc_errfile = local_lc_errfile;
           30  +		lc_errline = local_lc_errline;
    24     31   		lc_errno = LC_ERR_INVDATA;
    25     32   		return(-1);
    26     33   	}
    27     34   
    28     35   	configfp = lc_fopen(configfile, "r");
    29     36   
    30     37   	if (configfp == NULL) {
           38  +		lc_errfile = local_lc_errfile;
           39  +		lc_errline = local_lc_errline;
    31     40   		lc_errno = LC_ERR_CANTOPEN;
    32     41   		return(-1);
    33     42   	}
    34     43   
    35     44   	while (1) {
    36         -		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
           45  +		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
    37     46   		if (fgetsret == NULL) {
    38     47   			break;
    39     48   		}
    40         -		if (feof(configfp)) {
           49  +		if (lc_feof(configfp)) {
    41     50   			break;
    42     51   		}
           52  +
           53  +		local_lc_errline++;
    43     54   
    44     55   		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
    45     56   		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
    46     57   			*linebuf_ptr = '\0';
    47     58   			linebuf_ptr--;
    48     59   		}
    49     60   
................................................................................
    80     91   #endif
    81     92   				lc_errno = LC_ERR_INVCMD;
    82     93   			} else {
    83     94   #ifdef DEBUG
    84     95   				fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
    85     96   #endif
    86     97   			}
           98  +			lc_errfile = local_lc_errfile;
           99  +			lc_errline = local_lc_errline;
    87    100   			retval = -1;
    88    101   		} else {
    89    102   			lc_errno = save_lc_errno;
    90    103   		}
    91    104   	}
    92    105   
    93         -	fclose(configfp);
          106  +	lc_fclose(configfp);
    94    107   
    95    108   	return(retval);
    96    109   }

Modified configure.ac from [9c0f5749ef] to [e806c2cabd].

     1      1   AC_REVISION($Revision $)
     2         -AC_INIT(libconfig, 0.1.18)
            2  +AC_INIT(libconfig, 0.1.19)
     3      3   AC_CONFIG_HEADER(config.h)
     4      4   
     5      5   dnl Find out about the host OS
     6      6   DC_CHK_OS_INFO
     7      7   
     8      8   dnl Checks for programs.
     9      9   AC_PROG_CC

Modified libconfig.c from [9adb43042b] to [341b40c218].

    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_errfile = NULL;
    41     42   int lc_optind = 0;
           43  +int lc_errline = 0;
    42     44   
    43     45   extern char **environ;
    44     46   
    45         -static int lc_process_var_string(void *data, const char *value) {
           47  +static int lc_process_var_string(void *data, const char *value, const char **endptr) {
    46     48   	char **dataval;
    47     49   
    48     50   	dataval = data;
    49     51   	*dataval = strdup(value);
    50     52   
           53  +	*endptr = NULL;
           54  +
    51     55   	return(0);
    52     56   }
    53     57   
    54         -static int lc_process_var_cidr(void *data, const char *value) {
           58  +static int lc_process_var_cidr(void *data, const char *value, const char **endptr) {
           59  +	return(-1);
           60  +}
           61  +
           62  +static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
    55     63   	return(-1);
    56     64   }
    57     65   
    58         -static int lc_process_var_hostname6(void *data, const char *value) {
           66  +static int lc_process_var_hostname4(void *data, const char *value, const char **endptr) {
    59     67   	return(-1);
    60     68   }
    61     69   
    62         -static int lc_process_var_hostname4(void *data, const char *value) {
           70  +static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {
    63     71   	return(-1);
    64     72   }
    65     73   
    66         -static int lc_process_var_ip6(void *data, const char *value) {
    67         -	return(-1);
    68         -}
    69         -
    70         -static int lc_process_var_ip4(void *data, const char *value) {
           74  +static int lc_process_var_ip4(void *data, const char *value, const char **endptr) {
    71     75   	uint32_t *dataval, retval = 0;
    72     76   	const char *dotptr = NULL;
    73     77   	int tmpval = -1;
    74     78   //	int dotcount
    75     79   
    76     80   	dataval = data;
    77     81   
................................................................................
    94     98   			break;
    95     99   		}
    96    100   		dotptr++;
    97    101   	}
    98    102   
    99    103   	*dataval = retval;
   100    104   
          105  +	*endptr = (char *) dotptr;
          106  +
   101    107   	return(0);
   102    108   }
   103    109   
   104         -static int lc_process_var_longlong(void *data, const char *value) {
          110  +static int lc_process_var_longlong(void *data, const char *value, const char **endptr) {
   105    111   	long long *dataval;
   106    112   
   107    113   	dataval = data;
   108         -	*dataval = strtoll(value, NULL, 10);
          114  +	*dataval = strtoll(value, (char **) endptr, 10);
          115  +
          116  +	return(0);
          117  +}
          118  +
          119  +static int lc_process_var_long(void *data, const char *value, const char **endptr) {
          120  +	long *dataval;
          121  +
          122  +	dataval = data;
          123  +	*dataval = strtoll(value, (char **) endptr, 10);
   109    124   
   110    125   	return(0);
   111    126   }
   112    127   
   113         -static int lc_process_var_long(void *data, const char *value) {
   114         -	long *dataval;
          128  +static int lc_process_var_int(void *data, const char *value, const char **endptr) {
          129  +	int *dataval;
   115    130   
   116    131   	dataval = data;
   117         -	*dataval = strtoll(value, NULL, 10);
          132  +	*dataval = strtoll(value, (char **) endptr, 10);
   118    133   
   119    134   	return(0);
   120    135   }
   121    136   
   122         -static int lc_process_var_int(void *data, const char *value) {
   123         -	int *dataval;
          137  +static int lc_process_var_short(void *data, const char *value, const char **endptr) {
          138  +	short *dataval;
   124    139   
   125    140   	dataval = data;
   126         -	*dataval = strtoll(value, NULL, 10);
          141  +	*dataval = strtoll(value, (char **) endptr, 10);
   127    142   
   128    143   	return(0);
   129    144   }
   130    145   
   131         -static int lc_process_var_short(void *data, const char *value) {
   132         -	short *dataval;
   133         -
   134         -	dataval = data;
   135         -	*dataval = strtoll(value, NULL, 10);
   136         -
   137         -	return(0);
   138         -}
   139         -
   140         -static int lc_process_var_bool_byexistance(void *data, const char *value) {
          146  +static int lc_process_var_bool_byexistance(void *data, const char *value, const char **endptr) {
   141    147   	int *dataval;
   142    148   
   143    149   	dataval = data;
   144    150   
   145    151   	*dataval = 1;
   146    152   
          153  +	*endptr = NULL;
          154  +
   147    155   	return(0);
   148    156   }
   149    157   
   150         -static int lc_process_var_bool(void *data, const char *value) {
          158  +static int lc_process_var_bool(void *data, const char *value, const char **endptr) {
          159  +	char *trueval[] = {"enable", "true", "yes", "on", "y", "1"};
          160  +	char *falseval[] = {"disable", "false", "no", "off", "n", "0"};
          161  +	size_t chkvallen, vallen;
   151    162   	int *dataval;
          163  +	int i;
   152    164   
   153    165   	dataval = data;
   154    166   
   155    167   	*dataval = -1;
   156    168   
   157         -	if (strcasecmp(value, "enable") == 0 ||
   158         -	    strcasecmp(value, "true") == 0 ||
   159         -	    strcasecmp(value, "yes") == 0 ||
   160         -	    strcasecmp(value, "on") == 0 ||
   161         -            strcasecmp(value, "y") == 0 ||
   162         -	    strcasecmp(value, "1") == 0) {
   163         -		*dataval = 1;
   164         -		return(0);
   165         -	} else if (strcasecmp(value, "disable") == 0 ||
   166         -	    strcasecmp(value, "false") == 0 ||
   167         -	    strcasecmp(value, "off") == 0 ||
   168         -	    strcasecmp(value, "no") == 0 ||
   169         -            strcasecmp(value, "n") == 0 ||
   170         -	    strcasecmp(value, "0") == 0) {
   171         -		*dataval = 0;
   172         -		return(0);
          169  +	vallen = strlen(value);
          170  +
          171  +	for (i = 0; i < (sizeof(trueval) / sizeof(*trueval)); i++) {
          172  +		chkvallen = strlen(trueval[i]);
          173  +
          174  +		/*
          175  +		 * Skip if there's no way we could find a match here.
          176  +		 */
          177  +		if (chkvallen > vallen) {
          178  +			continue;
          179  +		}
          180  +
          181  +		/*
          182  +		 * Skip if there is no partial match.
          183  +		 */
          184  +		if (strncasecmp(value, trueval[i], chkvallen) != 0) {
          185  +			continue;
          186  +		}
          187  +
          188  +		if (value[chkvallen] == '\0' || value[chkvallen] == ',' || \
          189  +		    value[chkvallen] == ' ') {
          190  +			/* Declare a winner and set the next token. */
          191  +			*endptr = value + chkvallen;
          192  +			*dataval = 1;
          193  +			return(0);
          194  +		}
          195  +	}
          196  +
          197  +	for (i = 0; i < (sizeof(falseval) / sizeof(*falseval)); i++) {
          198  +		chkvallen = strlen(falseval[i]);
          199  +
          200  +		/*
          201  +		 * Skip if there's no way we could find a match here.
          202  +		 */
          203  +		if (chkvallen > vallen) {
          204  +			continue;
          205  +		}
          206  +
          207  +		/*
          208  +		 * Skip if there is no partial match.
          209  +		 */
          210  +		if (strncasecmp(value, falseval[i], chkvallen) != 0) {
          211  +			continue;
          212  +		}
          213  +
          214  +		if (value[chkvallen] == '\0' || value[chkvallen] == ',' || \
          215  +		    value[chkvallen] == ' ') {
          216  +			/* Declare a winner and set the next token. */
          217  +			*endptr = value + chkvallen;
          218  +			*dataval = 0;
          219  +			return(0);
          220  +		}
   173    221   	}
   174    222   
   175    223   	lc_errno = LC_ERR_BADFORMAT;
   176    224   	return(-1);
   177    225   }
   178    226   
   179         -static long long lc_process_size(const char *value) {
   180         -	long long retval = -1;
          227  +static unsigned long long lc_process_size(const char *value, const char **endptr) {
          228  +	unsigned long long retval = 0;
   181    229   	char *mult = NULL;
   182    230   
   183    231   	retval = strtoll(value, &mult, 10);
   184    232   	if (mult != NULL) {
   185    233   		switch (tolower(mult[0])) {
   186    234   			case 'p':
   187    235   				retval *= 1125899906842624LLU;
................................................................................
   202    250   				break;
   203    251   		}
   204    252   	}
   205    253   
   206    254   	return(retval);
   207    255   }
   208    256   
   209         -static int lc_process_var_sizelonglong(void *data, const char *value) {
          257  +static int lc_process_var_sizelonglong(void *data, const char *value, const char **endptr) {
   210    258   	long long *dataval;
   211    259   
   212    260   	dataval = data;
   213         -	*dataval = lc_process_size(value);
          261  +	*dataval = lc_process_size(value, endptr);
          262  +
          263  +	return(0);
          264  +}
          265  +
          266  +static int lc_process_var_sizelong(void *data, const char *value, const char **endptr) {
          267  +	long *dataval;
          268  +
          269  +	dataval = data;
          270  +	*dataval = lc_process_size(value, endptr);
   214    271   
   215    272   	return(0);
   216    273   }
   217    274   
   218         -static int lc_process_var_sizelong(void *data, const char *value) {
   219         -	long *dataval;
          275  +static int lc_process_var_sizeint(void *data, const char *value, const char **endptr) {
          276  +	int *dataval;
   220    277   
   221    278   	dataval = data;
   222         -	*dataval = lc_process_size(value);
          279  +	*dataval = lc_process_size(value, endptr);
   223    280   
   224    281   	return(0);
   225    282   }
   226    283   
   227         -static int lc_process_var_sizeint(void *data, const char *value) {
   228         -	int *dataval;
          284  +static int lc_process_var_sizeshort(void *data, const char *value, const char **endptr) {
          285  +	short *dataval;
   229    286   
   230    287   	dataval = data;
   231         -	*dataval = lc_process_size(value);
          288  +	*dataval = lc_process_size(value, endptr);
   232    289   
   233    290   	return(0);
   234    291   }
   235    292   
   236         -static int lc_process_var_sizeshort(void *data, const char *value) {
   237         -	short *dataval;
   238         -
   239         -	dataval = data;
   240         -	*dataval = lc_process_size(value);
   241         -
   242         -	return(0);
   243         -}
   244         -
   245         -static int lc_process_var_sizesizet(void *data, const char *value) {
          293  +static int lc_process_var_sizesizet(void *data, const char *value, const char **endptr) {
   246    294   	size_t *dataval;
   247    295   
   248    296   	dataval = data;
   249         -	*dataval = lc_process_size(value);
          297  +	*dataval = lc_process_size(value, endptr);
   250    298   
   251    299   	return(0);
   252    300   }
   253    301   
   254    302   
   255    303   static int lc_handle_type(lc_var_type_t type, const char *value, void *data) {
          304  +	const char *next;
          305  +	int is_list;
          306  +
          307  +	is_list = type & LC_VAR_LIST;
          308  +
          309  +	if (is_list == LC_VAR_LIST) {
          310  +	}
          311  +
   256    312   	switch (type) {
   257    313   		case LC_VAR_STRING:
   258         -			return(lc_process_var_string(data, value));
          314  +			return(lc_process_var_string(data, value, &next));
   259    315   			break;
   260    316   		case LC_VAR_LONG_LONG:
   261         -			return(lc_process_var_longlong(data, value));
          317  +			return(lc_process_var_longlong(data, value, &next));
   262    318   			break;
   263    319   		case LC_VAR_LONG:
   264         -			return(lc_process_var_long(data, value));
          320  +			return(lc_process_var_long(data, value, &next));
   265    321   			break;
   266    322   		case LC_VAR_INT:
   267         -			return(lc_process_var_int(data, value));
          323  +			return(lc_process_var_int(data, value, &next));
   268    324   			break;
   269    325   		case LC_VAR_SHORT:
   270         -			return(lc_process_var_short(data, value));
          326  +			return(lc_process_var_short(data, value, &next));
   271    327   			break;
   272    328   		case LC_VAR_BOOL:
   273         -			return(lc_process_var_bool(data, value));
          329  +			return(lc_process_var_bool(data, value, &next));
   274    330   			break;
   275    331   		case LC_VAR_SIZE_LONG_LONG:
   276         -			return(lc_process_var_sizelonglong(data, value));
          332  +			return(lc_process_var_sizelonglong(data, value, &next));
   277    333   			break;
   278    334   		case LC_VAR_SIZE_LONG:
   279         -			return(lc_process_var_sizelong(data, value));
          335  +			return(lc_process_var_sizelong(data, value, &next));
   280    336   			break;
   281    337   		case LC_VAR_SIZE_INT:
   282         -			return(lc_process_var_sizeint(data, value));
          338  +			return(lc_process_var_sizeint(data, value, &next));
   283    339   			break;
   284    340   		case LC_VAR_SIZE_SHORT:
   285         -			return(lc_process_var_sizeshort(data, value));
          341  +			return(lc_process_var_sizeshort(data, value, &next));
   286    342   			break;
   287    343   		case LC_VAR_BOOL_BY_EXISTANCE:
   288         -			return(lc_process_var_bool_byexistance(data, value));
          344  +			return(lc_process_var_bool_byexistance(data, value, &next));
   289    345   			break;
   290    346   		case LC_VAR_SIZE_SIZE_T:
   291         -			return(lc_process_var_sizesizet(data, value));
          347  +			return(lc_process_var_sizesizet(data, value, &next));
   292    348   			break;
   293    349   		case LC_VAR_IP:
   294    350   		case LC_VAR_IP4:
   295         -			return(lc_process_var_ip4(data, value));
          351  +			return(lc_process_var_ip4(data, value, &next));
   296    352   			break;
   297    353   		case LC_VAR_IP6:
   298         -			return(lc_process_var_ip6(data, value));
          354  +			return(lc_process_var_ip6(data, value, &next));
   299    355   			break;
   300    356   		case LC_VAR_HOSTNAME4:
   301         -			return(lc_process_var_hostname4(data, value));
          357  +			return(lc_process_var_hostname4(data, value, &next));
   302    358   			break;
   303    359   		case LC_VAR_HOSTNAME6:
   304         -			return(lc_process_var_hostname6(data, value));
          360  +			return(lc_process_var_hostname6(data, value, &next));
   305    361   			break;
   306    362   		case LC_VAR_CIDR:
   307         -			return(lc_process_var_cidr(data, value));
          363  +			return(lc_process_var_cidr(data, value, &next));
   308    364   			break;
   309    365   		case LC_VAR_TIME:
   310    366   		case LC_VAR_DATE:
   311    367   		case LC_VAR_FILENAME:
   312    368   		case LC_VAR_DIRECTORY:
   313    369   #ifdef DEBUG
   314    370   			fprintf(stderr, "Not implemented yet!\n");
................................................................................
   365    421   	size_t appnamelen = 0;
   366    422   	char varnamebuf[128] = {0};
   367    423   	char **currvar;
   368    424   	char *sep = NULL, *value = NULL, *cmd = NULL;
   369    425   	char *ucase_appname = NULL, *ucase_appname_itr = NULL;
   370    426   	char *lastcomponent_handler = NULL;
   371    427   	int varnamelen = 0;
          428  +	char *local_lc_errfile;
          429  +	int local_lc_errline;
   372    430   
   373    431   	/* Make sure we have an environment to screw with, if not,
   374    432   	   no arguments were found to be in error */
   375    433   	if (environ == NULL || appname == NULL) {
   376    434   		return(0);
   377    435   	}
          436  +
          437  +	local_lc_errfile = "<environment>";
          438  +	local_lc_errline = 0;
   378    439   
   379    440   	/* Allocate and create our uppercase appname. */
   380    441   	ucase_appname = strdup(appname);
   381    442   	if (ucase_appname == NULL) {
          443  +		lc_errfile = local_lc_errfile;
          444  +		lc_errline = local_lc_errline;
   382    445   		lc_errno = LC_ERR_ENOMEM;
   383    446   		return(-1);
   384    447   	}
   385    448   	for (ucase_appname_itr = ucase_appname; *ucase_appname_itr != '\0'; ucase_appname_itr++) {
   386    449   		*ucase_appname_itr = toupper(*ucase_appname_itr);
   387    450   	}
   388    451   
................................................................................
   486    549   	char *lastcomponent_handler = NULL;
   487    550   	char **newargv = NULL;
   488    551   	char *usedargv = NULL;
   489    552   	int cmdargidx = 0;
   490    553   	int newargvidx = 0;
   491    554   	int retval = 0, chkretval = 0;
   492    555   	int ch = 0;
          556  +	char *local_lc_errfile;
          557  +	int local_lc_errline;
          558  +
          559  +	local_lc_errfile = "<cmdline>";
          560  +	local_lc_errline = 0;
   493    561   
   494    562   	/* Allocate "argc + 1" (+1 for the NULL terminator) elements. */
   495    563   	newargv = malloc((argc + 1) * sizeof(*newargv));
   496    564   	if (newargv == NULL) {
          565  +		lc_errfile = local_lc_errfile;
          566  +		lc_errline = local_lc_errline;
   497    567   		lc_errno = LC_ERR_ENOMEM;
   498    568   		return(-1);
   499    569   	}
   500    570   	newargv[newargvidx++] = argv[0];
   501    571   	newargv[argc] = NULL;
   502    572   
   503    573   	/* Allocate space to indicate which arguments have been used. */
   504    574   	usedargv = malloc(argc * sizeof(*usedargv));
   505    575   	if (usedargv == NULL) {
          576  +		lc_errfile = local_lc_errfile;
          577  +		lc_errline = local_lc_errline;
   506    578   		lc_errno = LC_ERR_ENOMEM;
   507    579   		free(newargv);
   508    580   		return(-1);
   509    581   	}
   510    582   	for (cmdargidx = 0; cmdargidx < argc; cmdargidx++) {
   511    583   		usedargv[cmdargidx] = 0;
   512    584   	}
................................................................................
   515    587   		cmdarg = argv[cmdargidx];
   516    588   
   517    589   		/* Make sure we have an argument here. */
   518    590   		if (cmdarg == NULL) {
   519    591   			break;
   520    592   		}
   521    593   
   522         -		/* If the argument isn't an option, abort. */
          594  +		/* If the argument isn't an option, skip. */
   523    595   		if (cmdarg[0] != '-') {
   524    596   			continue;
   525    597   		}
   526    598   
   527    599   		/* Setup a pointer in the new array for the actual argument. */
   528    600   		newargv[newargvidx++] = cmdarg;
   529    601   		usedargv[cmdargidx] = 1;
................................................................................
   581    653   
   582    654   				if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) {
   583    655   					cmdoptarg = NULL;
   584    656   				} else {
   585    657   					cmdargidx++;
   586    658   					if (cmdargidx >= argc) {
   587    659   						fprintf(stderr, "Argument required.\n");
          660  +						lc_errfile = local_lc_errfile;
          661  +						lc_errline = local_lc_errline;
   588    662   						lc_errno = LC_ERR_BADFORMAT;
   589    663   						free(usedargv);
   590    664   						free(newargv);
   591    665   						return(-1);
   592    666   					}
   593    667   					cmdoptarg = argv[cmdargidx];
   594    668   					newargv[newargvidx++] = cmdoptarg;
................................................................................
   601    675   				}
   602    676   
   603    677   				break;
   604    678   			}
   605    679   
   606    680   			if (handler == NULL) {
   607    681   				fprintf(stderr, "Unknown option: --%s\n", cmdarg);
          682  +				lc_errfile = local_lc_errfile;
          683  +				lc_errline = local_lc_errline;
   608    684   				lc_errno = LC_ERR_INVCMD;
   609    685   				free(usedargv);
   610    686   				free(newargv);
   611    687   				return(-1);
   612    688   			}
   613    689   		} else {
   614    690   			for (; *cmdarg != '\0'; cmdarg++) {
................................................................................
   629    705   
   630    706   					if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) {
   631    707   						cmdoptarg = NULL;
   632    708   					} else {
   633    709   						cmdargidx++;
   634    710   						if (cmdargidx >= argc) {
   635    711   							fprintf(stderr, "Argument required.\n");
          712  +							lc_errfile = local_lc_errfile;
          713  +							lc_errline = local_lc_errline;
   636    714   							lc_errno = LC_ERR_BADFORMAT;
   637    715   							free(usedargv);
   638    716   							free(newargv);
   639    717   							return(-1);
   640    718   						}
   641    719   						cmdoptarg = argv[cmdargidx];
   642    720   						newargv[newargvidx++] = cmdoptarg;
   643    721   						usedargv[cmdargidx] = 1;
   644    722   					}
   645    723   
   646    724   					chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
   647    725   					if (chkretval < 0) {
          726  +						lc_errfile = local_lc_errfile;
          727  +						lc_errline = local_lc_errline;
   648    728   						retval = -1;
   649    729   					}
   650    730   
   651    731   					break;
   652    732   				}
   653    733   
   654    734   				if (handler == NULL) {
   655    735   					fprintf(stderr, "Unknown option: -%c\n", ch);
          736  +					lc_errfile = local_lc_errfile;
          737  +					lc_errline = local_lc_errline;
   656    738   					lc_errno = LC_ERR_INVCMD;
   657    739   					free(usedargv);
   658    740   					free(newargv);
   659    741   					return(-1);
   660    742   				}
   661    743   			}
   662    744   		}
................................................................................
   937   1019   
   938   1020   	lc_errno = LC_ERR_NONE;
   939   1021   
   940   1022   	return(retval);
   941   1023   }
   942   1024   
   943   1025   char *lc_geterrstr(void) {
   944         -	char *retval = NULL;
         1026  +	static char retval[512];
         1027  +	char *errmsg = NULL;
   945   1028   
   946   1029   	switch (lc_errno) {
   947   1030   		case LC_ERR_NONE:
   948         -			retval = "Success";
         1031  +			errmsg = "Success";
   949   1032   			break;
   950   1033   		case LC_ERR_INVCMD:
   951         -			retval = "Invalid command";
         1034  +			errmsg = "Invalid command or option";
   952   1035   			break;
   953   1036   		case LC_ERR_INVSECTION:
   954         -			retval = "Invalid section";
         1037  +			errmsg = "Invalid section";
   955   1038   			break;
   956   1039   		case LC_ERR_INVDATA:
   957         -			retval = "Invalid application data (internal error)";
         1040  +			errmsg = "Invalid application data (internal error)";
   958   1041   			break;
   959   1042   		case LC_ERR_BADFORMAT:
   960         -			retval = "Bad data specified or incorrect format.";
         1043  +			errmsg = "Bad data specified or incorrect format.";
   961   1044   			break;
   962   1045   		case LC_ERR_CANTOPEN:
   963         -			retval = "Can't open file.";
         1046  +			errmsg = "Can't open file.";
   964   1047   			break;
   965   1048   		case LC_ERR_CALLBACK:
   966         -			retval = "Error return from application handler.";
         1049  +			errmsg = "Error return from application handler.";
   967   1050   			break;
   968   1051   		case LC_ERR_ENOMEM:
   969         -			retval = "Insuffcient memory.";
         1052  +			errmsg = "Insuffcient memory.";
   970   1053   			break;
   971   1054   	}
   972   1055   
   973         -	lc_errno = LC_ERR_NONE;
         1056  +	/*
         1057  +	 * This is not part of the switch statement so we will get warnings
         1058  +	 * about unhandled enum values.
         1059  +	 */
         1060  +	if (errmsg == NULL) {
         1061  +		errmsg = "Unknown error";
         1062  +	}
   974   1063   
   975         -	if (retval != NULL) {
   976         -		return(retval);
         1064  +	if (lc_errfile == NULL) {
         1065  +		snprintf(retval, sizeof(retval), "%s:%i: %s", "<no file>", lc_errline, errmsg);
         1066  +	} else {
         1067  +		snprintf(retval, sizeof(retval), "%s:%i: %s", lc_errfile, lc_errline, errmsg);
   977   1068   	}
   978         -	return("Unknown error");
         1069  +
         1070  +	retval[sizeof(retval) - 1] = '\0';
         1071  +
         1072  +	return(retval);
   979   1073   }

Modified libconfig.h.in from [46fa13e1cf] to [6dd0b27349].

     1      1   !ifndef _RSK_LIBCONFIG_H
     2      2   !define _RSK_LIBCONFIG_H
     3         -
     4      3   !ifdef __cplusplus
     5      4   extern "C" {
     6      5   !endif
            6  +
            7  +__BLANK_LINE__
            8  +
            9  +!define LC_VAR_LIST 0x80
           10  +
     7     11   __BLANK_LINE__
     8     12   
     9     13   typedef enum {
    10     14           LC_CONF_SECTION,
    11     15           LC_CONF_APACHE,
    12     16           LC_CONF_COLON,
    13     17           LC_CONF_EQUAL,
................................................................................
    35     39           LC_VAR_TIME,
    36     40           LC_VAR_DATE,
    37     41           LC_VAR_SECTION,
    38     42           LC_VAR_SECTIONSTART,
    39     43           LC_VAR_SECTIONEND,
    40     44           LC_VAR_BOOL_BY_EXISTANCE,
    41     45           LC_VAR_SIZE_SIZE_T,
    42         -	LC_VAR_CIDR,
    43         -	LC_VAR_IP,
    44         -	LC_VAR_IP4,
    45         -	LC_VAR_IP6,
    46         -	LC_VAR_HOSTNAME4,
    47         -	LC_VAR_HOSTNAME6,
           46  +        LC_VAR_CIDR,
           47  +        LC_VAR_IP,
           48  +        LC_VAR_IP4,
           49  +        LC_VAR_IP6,
           50  +        LC_VAR_HOSTNAME4,
           51  +        LC_VAR_HOSTNAME6,
    48     52   } lc_var_type_t;
    49     53   
    50     54   __BLANK_LINE__
    51     55   
    52     56   typedef enum {
    53     57           LC_FLAGS_VAR,
    54     58           LC_FLAGS_CMDLINE,
................................................................................
    87     91   !define LC_CBRET_ERROR (-1)
    88     92   
    89     93   __BLANK_LINE__
    90     94   
    91     95   extern int lc_optind;
    92     96   
    93     97   __BLANK_LINE__
           98  +
    94     99   !ifdef __cplusplus
    95    100   }
    96    101   !endif
    97         -
    98    102   !endif

Modified libconfig_private.h from [0dfd11fd0f] to [8f8355315c].

     1      1   #ifndef _RSK_LIBCONFIG_PRIVATE_H
     2      2   #define _RSK_LIBCONFIG_PRIVATE_H
     3      3   
     4      4   #include "libconfig.h"
     5      5   
     6      6   extern lc_err_t lc_errno;
            7  +extern int lc_errline;
            8  +extern const char *lc_errfile;
     7      9   
     8     10   int lc_process_var(const char *var, const char *varargs, const char *value, lc_flags_t flags);
     9     11   
    10     12   struct lc_varhandler_st;
    11     13   
    12     14   struct lc_varhandler_st {
    13     15   	struct lc_varhandler_st *_next;

Modified test-lc.c from [5bdc823df0] to [ae325a3444].

    32     32   int main(int argc, char **argv) {
    33     33   	char *joeval = NULL;
    34     34   	size_t xval = -1;
    35     35   	int onoff = -1;
    36     36   	int lcpret = -1;
    37     37   	int i = 0;
    38     38   	int onoff2 = 0;
    39         -	uint32_t ipaddr;
           39  +	uint32_t ipaddr = 0;
    40     40   
    41     41   	lc_register_var("Section", LC_VAR_SECTION, NULL, 0);
    42     42   	lc_register_var("Somesection", LC_VAR_SECTION, NULL, 0);
    43     43   	lc_register_var("Section.Test", LC_VAR_STRING, &joeval, 'j');
    44     44   	lc_register_var("bob", LC_VAR_SIZE_SIZE_T, &xval, 's');
    45     45   	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
    46     46   	lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
    47     47   	lc_register_var("ipaddr", LC_VAR_IP, &ipaddr, 'i');
    48     48   	lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
    49     49   	lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
    50     50   	lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
    51         -	lcpret = lc_process_file("testapp", "http://10.8.0.2/test.conf", LC_CONF_APACHE);
           51  +	lcpret = lc_process_file("testapp", "build/test.conf", LC_CONF_APACHE);
           52  +	if (lcpret < 0) {
           53  +		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
           54  +		return(EXIT_FAILURE);
           55  +	}
           56  +
    52     57   	lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
    53         -	lc_cleanup();
    54     58   	if (lcpret < 0) {
    55     59   		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
    56     60   		return(EXIT_FAILURE);
    57     61   	}
           62  +
           63  +	lc_cleanup();
    58     64   
    59     65   	if (joeval != NULL) {
    60     66   		fprintf(stderr, "joeval = \"%s\"\n", joeval);
    61     67   	} else {
    62     68   		fprintf(stderr, "joeval = \"(null)\"\n");
    63     69   	}
    64     70   	fprintf(stderr, "xval = %llu\n", (unsigned long long) xval);