From owner-freebsd-chat Tue Jan 18 7:28:48 2000 Delivered-To: freebsd-chat@freebsd.org Received: from ren.detir.qld.gov.au (ns.detir.qld.gov.au [203.46.81.66]) by hub.freebsd.org (Postfix) with ESMTP id 85CC614DE6 for ; Tue, 18 Jan 2000 07:28:43 -0800 (PST) (envelope-from syssgm@detir.qld.gov.au) Received: by ren.detir.qld.gov.au; id BAA13434; Wed, 19 Jan 2000 01:28:31 +1000 (EST) Received: from ogre.detir.qld.gov.au(167.123.8.3) via SMTP by ren.detir.qld.gov.au, id smtpd013432; Wed Jan 19 01:28:24 2000 Received: from atlas.detir.qld.gov.au (atlas.detir.qld.gov.au [167.123.8.9]) by ogre.detir.qld.gov.au (8.8.8/8.8.7) with ESMTP id BAA24480; Wed, 19 Jan 2000 01:27:58 +1000 (EST) Received: from nymph.detir.qld.gov.au (nymph.detir.qld.gov.au [167.123.10.10]) by atlas.detir.qld.gov.au (8.8.5/8.8.5) with ESMTP id BAA14218; Wed, 19 Jan 2000 01:27:57 +1000 (EST) Received: from nymph.detir.qld.gov.au (localhost [127.0.0.1]) by nymph.detir.qld.gov.au (8.9.3/8.8.7) with ESMTP id BAA43810; Wed, 19 Jan 2000 01:27:56 +1000 (EST) (envelope-from syssgm@nymph.detir.qld.gov.au) Message-Id: <200001181527.BAA43810@nymph.detir.qld.gov.au> To: Jonathon McKitrick Cc: freebsd-chat@freebsd.org, syssgm@detir.qld.gov.au Subject: Re: For any sick-in-the-head C programmers References: <20000118082126.A7006@keltia.freenix.fr> In-Reply-To: from Jonathon McKitrick at "Tue, 18 Jan 2000 14:36:07 +0000" Date: Wed, 19 Jan 2000 01:27:56 +1000 From: Stephen McKay Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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