liboptcfg

diff src/optcfg.c @ 2:9c73004c7af3

works
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 20 Nov 2015 17:05:39 +0200
parents 8fd2858c6a29
children a6f127f3408d
line diff
     1.1 --- a/src/optcfg.c	Sat Nov 14 14:12:30 2015 +0200
     1.2 +++ b/src/optcfg.c	Fri Nov 20 17:05:39 2015 +0200
     1.3 @@ -159,7 +159,7 @@
     1.4  
     1.5  	len = strlen(line);
     1.6  	buf = alloca(len + 1);
     1.7 -	memcpy(buf, line, len);
     1.8 +	memcpy(buf, line, len + 1);
     1.9  
    1.10  	start = skip_spaces(buf);
    1.11  	strip_comments(start);
    1.12 @@ -188,6 +188,20 @@
    1.13  	return 0;
    1.14  }
    1.15  
    1.16 +int optcfg_enabled_value(struct optcfg *oc, int *enabledp)
    1.17 +{
    1.18 +	if(oc->argidx) {
    1.19 +		*enabledp = 1; /* TODO take -no- prefix into account */
    1.20 +	} else {
    1.21 +		char *val = optcfg_next_value(oc);
    1.22 +		if(optcfg_bool_value(val, enabledp) == -1) {
    1.23 +			return -1;
    1.24 +		}
    1.25 +	}
    1.26 +	return 0;
    1.27 +}
    1.28 +
    1.29 +
    1.30  char *optcfg_next_value(struct optcfg *oc)
    1.31  {
    1.32  	if(oc->argidx) {	/* we're in the middle of parsing arguments, so get the next one */
    1.33 @@ -314,6 +328,7 @@
    1.34  	*eq = 0;
    1.35  	strip_trailing_spaces(line);
    1.36  	val = skip_spaces(eq + 1);
    1.37 +	strip_trailing_spaces(val);
    1.38  
    1.39  	if(!*line || !*val) {
    1.40  		return 0;