Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jan 2000 01:27:56 +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:  <200001181527.BAA43810@nymph.detir.qld.gov.au>
In-Reply-To: <Pine.BSF.4.21.0001181435410.32110-100000@dogma.freebsd-uk.eu.org> from Jonathon McKitrick at "Tue, 18 Jan 2000 14:36:07 %2B0000"
References:  <20000118082126.A7006@keltia.freenix.fr> <Pine.BSF.4.21.0001181435410.32110-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:

>On Tue, 18 Jan 2000, Ollivier Robert wrote:
>
>>> #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))
>
>So can someone explain what this actually *does*?

You don't like obfuscated C puzzles?  :-)

Together with the other macros, it does all that getopt(3) does.  It's
rather clever, if poorly formatted.  It even recognises '--' and stops
option processing, and handles optional spaces before option arguments.

The state variable _O is 0 initially (to enable skipping the program name),
1 when just about to look at a command line argument to see if it is an
option, 2 when it's seen '-' and is part way through a list of flags, and
4 when there are no more option flags.  (3 isn't used because _O&2 is
shorter than _O==2.)  Then ARG() is used to read the file arguments.

This stuff was really fun back at University, but in the real world it
just gets you beaten to death by maintenance programmers.

Stephen.


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?200001181527.BAA43810>