confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Confuse-devel] confuse 2.0: list of values


From: Martin Hedenfalk
Subject: Re: [Confuse-devel] confuse 2.0: list of values
Date: Wed, 2 Jul 2003 01:07:36 +0200

Hi Juraj,

The _LIST initialization macros expect the default value as a string in the same format as in the configuration file. In this case, the ImageQuality list should be initialized to the empty list with:

CFG_INT_LIST("ImageQuality", "{}", 0)

I agree this is a bit confusing, passing 0 (or NULL, or even the empty string "") as the default value should also initialize to the empty list. I've now changed the init function to do this.

You also found another bug: setting a list option to the empty list in the configuration file should of course work, no matter what the default value is. Well, now it does.

The updated source is in the CVS repository. There should be a version 2.1 soon (no promise of _how_ soon though :-).

Thanks / martin


tisdagen den 1 juli 2003 kl 13.21 skrev Juraj Variny:

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

--
Martin Hedenfalk <address@hidden>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]