4 ms·
this is how they did it somewhat later in plan 9, with macro's: ARGBEGIN{ default: usage(); case 'm': m = ARGF(); break; case 'p': pfl
by mjl- 9y ago
this is how they did it somewhat later in plan 9, with macro's:
ARGBEGIN{
default:
usage();
case 'm':
m = ARGF();
break;
case 'p':
pflag = 1;
break;
}ARGEND
https://github.com/9fans/plan9port/blob/master/include/libc.h#L919-L940 https://github.com/9fans/plan9port/blob/master/include/libc....
https://github.com/9fans/plan9port/blob/master/src/cmd/mkdir.c#L57-L71 https://github.com/9fans/plan9port/blob/master/src/cmd/mkdir...
- henesy 9y agoThe Plan 9 solution always felt really logical imo.
- mjl- 9y agoi agree. too "clever", feels like a needless optimization. (optimizing for fewer keystrokes to type? or obscurity?) btw, many of the plan 9 commands use slightly different/custom option parsing. probably for historic reasons.
- mveety 9y agoNo, this isn't clever at all. Its an optimization for when you need to write a lot of little utilities that need to parse arguments. It probably came out of a day of writing tools, and after the fifth time of rewriting that while/for loop someone got pissed and made that macro. I use this macro all the time on both 9front and unix because it makes parsing arguments trivial (and I don't use long options, but that's more because I'm a plan 9/unix extremist than for any technical reasons).