Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jan 2000 01:50:22 +1000
From:      Stephen McKay <syssgm@detir.qld.gov.au>
To:        Jonathon McKitrick <jcm@dogma.freebsd-uk.eu.org>
Cc:        freebsd-chat@freebsd.org, syssgm@detir.qld.gov.au
Subject:   Re: For any sick-in-the-head C programmers 
Message-ID:  <200001181550.BAA44174@nymph.detir.qld.gov.au>
In-Reply-To: <Pine.BSF.4.21.0001181534340.33173-100000@dogma.freebsd-uk.eu.org> from Jonathon McKitrick at "Tue, 18 Jan 2000 15:34:48 %2B0000"
References:  <Pine.BSF.4.21.0001181534340.33173-100000@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, 18th January 2000, Jonathon McKitrick wrote:

>Is there a way to format that macro so it is more readable?

I've not tried compiling it, but this should be equivalent.  By the way,
clear layout shows that the & vs == trick saved 2 characters in total. :-)

/*************** Micro getopt() *********************************************/
#define OPTION(c,v)					\
    (							\
    _O&2 && **v						\
	? *(*v)++					\
	: !c || _O&4					\
	    ? 0						\
	    :   (					\
		!(_O&1) && (--c, ++v),			\
		_O=4,					\
		c && **v == '-' && v[0][1]		\
		    ? *++*v == '-' && !v[0][1]		\
			? (--c, ++v , 0)		\
			: (_O=2, *(*v)++)		\
		    : 0					\
		)					\
    )

#define OPTARG(c,v)					\
    (							\
    _O&2						\
	? **v || (++v, --c)				\
	    ? (_O=1, --c, *v++)				\
	    : (_O=4, (char*)0)				\
	: (char*)0					\
    )

#define OPTONLYARG(c,v)					\
    (							\
    _O&2 && **v						\
	? (_O=1, --c, *v++)				\
	: (char*)0					\
    )

#define ARG(c,v)					\
    (							\
    c							\
	? (--c, *v++)					\
	: (char*)0					\
    )

static int _O = 0;              /* Internal state */
/*************** Micro getopt() *********************************************/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001181550.BAA44174>