[asterisk-dev] Re: comments on this one ? (macros for parsing config file ?)

Luigi Rizzo rizzo at icir.org
Wed Nov 15 16:38:09 MST 2006


On Wed, Nov 15, 2006 at 09:47:22PM +0000, Tony Mountifield wrote:
> In article <200611151244.19357.tilghman at mail.jeffandtilghman.com>,
> Tilghman Lesher <tilghman at mail.jeffandtilghman.com> wrote:
> > On Wednesday 15 November 2006 12:32, Luigi Rizzo wrote:
> > > > I think they make this part of the code a lot more readable and
> > > > consistent and less error prone, especially because we can do the
> > > > same parsing on fields of the same type.
> > 
> > While it certainly makes the code smaller, I don't find it easier to
> > read, nor do I think it's less error-prone.  I think it's actually more
> > error prone, as it's difficult to read what the code is actually doing.
> > The problem is that this translation to macros makes the code
> > cryptic.  I'd almost compare it to using macros for the sake of using
> > macros, not for any legitimate benefit.
> 
> I agree. When trying to understand code with lots of macros, I spend
> most of my time looking back at the macro definitions to understand what
> is actually going on!

well, keep in mind that i hate macros so i'd rather not use them.
Ideally, i would set up something like this

	struct _f {
		const char *keyword;
		int (*handler)(void *args);
		void *args;
	} cfg_parse[] = {
		{ "callgroup", ast_get_group, &user->callgroup },
		{ "language", get_string, &user->language },
		{ "musicclass", get_string, &user->mohinterpret)
		...
	}

to configure how to parse the info. Unfortunately, in many cases
the action is an unnamed block of code and defining a function for it
is a bit overkill. Secondly, one argument often is not enough, e.g.
fetching a string into user->language requires passing sizeof(user->language) as well.

Anyways, the macros here are rather trivial - if you match the first
argument, you run the code in the second argument.

This said, i am just trying to figure out if, from the macro-based
version, there is a way to come up with some readable parsing code.
Worst case, this will look like a piece of yacc code, and i will
give up on it :)

	cheers
	luigi


More information about the asterisk-dev mailing list