confuse-devel
[Top][All Lists]
Advanced

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

Re: [Confuse-devel] config file versions and partial parsing


From: Martin Hedenfalk
Subject: Re: [Confuse-devel] config file versions and partial parsing
Date: Sun, 11 Jul 2004 16:58:27 +0200

Hi,

Ignoring unknown options would be a bit tricky, because then you wouldn't know how to parse them (lists for example are parsed differently from plain strings).

What you could do in your case is to require that the config-file-version option must be placed first in the config file. Then write a validating callback function which returns non-zero. A non-zero return from the callback will abort the parsing, but the callback is responsible for printing any error messages (which in your case would be none). The result from cfg_parse() will however be CFG_PARSE_ERROR, but you can set an internal flag in the validating callback to indicate success.

Then you can restart the parsing with a cfg_init() with the appropriate options.

To tell libConfuse about the validating callback function you use cfg_set_validate_func() after cfg_init().

Hope that helps
/Martin

2004-07-10 kl. 05.17 skrev Brett Russ:

Hi Martin,

First off, thank you for this excellent time saver you've written! It took a bit of searching to find but well worth it.

I am writing a program in which I've included a version number in my config file to allow me to change the format in the future if needed (add/move/remove options, etc). What I originally tried to do was similar to the following pseudo code:

opts {
   INT, "config-file-version"
   END
}

cfg = cfg_init()
cfg_parse(cfg, opts)
version = cfg_getint(cfg, "config-file-version")
cfg_free(cfg)

switch (version) {
case 1:
parse_v1();
break;
case 2:
....

and parse_v?() does a new parse, except this time with the complete list of options known to be in that version.

So basically, I was hoping for cfg_parse to only harvest the options I told it about in opts, which in this case was "config-file-version", and ignore everything else. I found that parse errors were given unless I identified everything beforehand.

I think for now I may have to parse for "config-file-version" myself, and once I have that number then switch on it and do only one libconfuse parse after I know what to expect.

Would this be a feature request you'd consider? A flag to allow for ignoring of all unlisted options? Or would this be leading down the answer given here:
http://lists.gnu.org/archive/html/confuse-devel/2003-09/msg00001.html ?

Either way, thanks again,
Brett






reply via email to

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