Hi,
I have a problem to make confuse distinguish whether there are some
values in
a list or whether the option is not present at all. I use this test
program:
#include <stdio.h>
#include <confuse.h>
static cfg_opt_t opts[] = {
CFG_INT_LIST("ImageQuality", 0, 0),
CFG_END()
};
int main(int argc, char**argv ){
cfg_t *cfg;
int n, i, status;
cfg = cfg_init(opts, CFGF_NOCASE);
if(argc == 2) status = cfg_parse(cfg, argv[1]);
else exit(1);
n = cfg_size(cfg, "ImageQuality");
printf("Number of values:%d\n", n);
for(i = 0; i < n; i++)
{
long q = cfg_getnint(cfg, "ImageQuality", i);
printf("Value #%d :%ld\n",i+1,q);
}
cfg_free(cfg);
return status;
}
When given empty/commented out config file, test program prints the
following:
Number of values:1
Value #1 :0
It does the same when list of values in config file is empty (i.e.
ImageQuality = {} ).
I tried also similar program with confuse 1.2.3. Only change was opts
bdeclaration:
static cfgopt_t opts[] = {
CFG_INT("ImageQuality", 0, CFGF_LIST),
CFG_END()
};
It behaves properly (I think), it prints just:
Number of values: 0
When there is non-empty list of values in config file, for example:
ImageQuality = {75,76,7,175}
all is OK, in all cases:
Number of values:4
Value #1 :75
Value #2 :76
Value #3 :7
Value #4 :175
I'm using Linux Mandrake 9.1 and compiled confuse myself without any
flags.
To summarize it all, I believe that in case of empty config file should
cfg_size() return 0, as it does in confuse 1.2.3. But in 2.0 it
returns 1,
as if there was option present with one value.
Juraj Variny