confuse-devel
[Top][All Lists]
Advanced

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

[Confuse-devel] pass-through defaults


From: Michael Grubb
Subject: [Confuse-devel] pass-through defaults
Date: Wed, 26 Mar 2008 13:59:43 -0500

Martin,
First let me commend you on a phenomenal piece of software!!
My question is: Is there an easier way to support pass-through defaults than using a validation callback, and if not what would be the safest way to accomplish this?

For example:

Given the following config snippet:

foo = val1
bar = 2

section one {
        oof = val3
}

And the following initialization:

        static cfg_opt_t section_opts[] = {
                CFG_STR("oof", NULL, CFGF_NONE),
                CFG_STR("foo", NULL, CFGF_NONE),
                CFG_INT("bar", 0, CFGF_NONE), 
                CFG_END()
        };

        static cfg_opt_t opts[] = {
                CFG_SEC("section", section_opts, CFGF_MULTI | CFGF_TITLE),
                CFG_STR("foo", NULL, CFGF_NONE),
                CFG_INT("bar", 3, CFGF_NONE),
                CFG_END()
        };


I'd like to be able to do:
cfg_t *sec = cfg_gettsec(cfg, "section", "one");
int bar = cfg_getint(sec, "bar");

And bar would be 2 (some global options could fall through to sections as default values).
So:
If root|bar = 2
And section one|bar is not set
Then section one|bar = 2

If root|bar is not set
And section one|bar  is not set
Then section one|bar = 3

If root|bar = 2
And section one|bar = 4
Then section one|bar = 4

If root|bar is not set
And section one|bar = 5
Then section one|bar = 5

I'm currently using a validating callback on section to somewhat simulate this behavior, but I'm having a hard time figuring out if the option is explicitly set to it's default value or if it wasn't set at all. (I'm also dealing with some string values in this manner.)

I don't figure this is directly available via the API (or I haven't found it yet), If this would be something rather simple and you could point me in the general direction of where to look, and you would be amenable to accepting a patch I don't mind hacking this in. Or if you could perhaps give me a few pointers or caveats to using the existing callback mechanism to simulate this.

Any help is greatly appreciated!.

Regards,

Michael Grubb




reply via email to

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