[Top][All Lists]

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

Re: [Nmh-workers] nmh internals: argument processing

From: Ralph Corderoy
Subject: Re: [Nmh-workers] nmh internals: argument processing
Date: Wed, 09 Jan 2013 12:09:10 +0000

Hi Ken,

> > With X(), returning the index remains sufficient because the enum
> > will always match the array so there's no need to also store the
> > index in the struct.  The two expansions of X(), enum and array,
> > could be in a central #include.
> I'm trying to envision how this would work.  You can't have them part
> of the same statement, because the enum and the elements of the struct
> swit array need to be two seperate statements.  Is that possible with
> the X() macro?  I'm not seeing it.

Hope this clairifies, ask if anything's unclear.

Taking 1.5's uip/mark.c, these first two could be central,

    #define DEFINE_SWITCH_ENUM(name) \
        enum { \
            name ## _SWITCHES \
            LEN_ ## name \

    #define DEFINE_SWITCH_ARRAY(name, array) \
        static struct swit array[] = { \
            name ## _SWITCHES \
            { NULL, 0 } \

and then these are in mark.c.

    #define MARK_SWITCHES \
        X("add", 0, ADDSW) \
        X("delete", 0, DELSW) \
        X("list", 0, LSTSW) \
        X("sequence name", 0, SEQSW) \
        X("public", 0, PUBLSW) \
        X("nopublic", 0, NPUBLSW) \
        X("zero", 0, ZEROSW) \
        X("nozero", 0, NZEROSW) \
        X("version", 0, VERSIONSW) \
        X("help", 0, HELPSW) \
        X("debug", -5, DEBUGSW) \

    #define X(sw, minchars, id) id,
    #undef X

    #define X(sw, minchars, id) { sw, minchars },
    #undef X

> Also, I don't think we can have it in a central include file, since there
> are some cases where there are two different struct swit arrays in the
> same source code file.

I added the `array' parameter to DEFINE_SWITCH_ARRAY();  before I just
always called the array `switches'.  The blank line after
MARK_SWITCHES's definition is significant.

The LEN_MARK enumerate is to avoid the trailing comma in an enum;
illegal in C89.  The name is embedded to make it unique and it's useful
on other occasions, e.g. not having to NULL-terminate the array.

Cheers, Ralph.

reply via email to

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