|
|
Subscribe / Log in / New account

An interview with Larry Wall (LinuxVoice)

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 16:21 UTC (Fri) by rsidd (subscriber, #2582)
In reply to: An interview with Larry Wall (LinuxVoice) by nevets
Parent article: An interview with Larry Wall (LinuxVoice)

Nice! Speaking of incomprehensible symbols, take a look at the getopt()-style macros in the FreeBSD chat.c from earlier years (sadly, they got rid of it circa 2008 in favour of "standard" getopt; sadly, also, lwn doesn't seem to accept the PRE tag, which precludes me from cut-pasting without much tediousness).


to post comments

Here are the getopt() macros (going off-topic)

Posted Jul 19, 2015 10:52 UTC (Sun) by pr1268 (guest, #24648) [Link] (1 responses)

/*************** 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	ARG(c,v)	(c?(--c,*v++):(char*)0)

God help whoever had to update/maintain that mess. I consider myself a fairly knowledgeable C programmer, but even that code makes me cringe...

Here are the getopt() macros (going off-topic)

Posted Jul 19, 2015 13:15 UTC (Sun) by lsl (subscriber, #86508) [Link]

I regularly use a set of macros written in the same spirit (but in a somewhat clearer way). I like them for their simplicity. Also there's no runtime support necessary, so you can use them anywhere, really.

There's also a variant (from the Inferno operating system) that supports arbitrary UTF8-encoded Unicode codepoints as flag characters:
https://bitbucket.org/inferno-os/inferno-os/src/tip/inclu...


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds