On Wed, Nov 15, 2006 at 09:47:22PM +0000, Tony Mountifield wrote:
> In article <[EMAIL PROTECTED]>,
> Tilghman Lesher <[EMAIL PROTECTED]> 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
_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to