If you like this sort of source code, I'd also recommend looking at the BSD standard utilities --- they have a similar simple and concise style.
Yet there's still one small simplification that can be made: the condition in the inner loop doesn't need "!= '\0'".
If there are many pure-binary options, then putting them in a bitflag is also an easy extension to the present code:
char binopts[] = "abcdefg";
char *opt;
if(opt = strchr(binopts, *s))
options |= 1 << (optidx - opt);
else
// put the switch(*s) here
Nowadays they just haul in the software weenies with their fancy objects and methods. Lost is the subtle art of manipulating arrays of pointers to strings of characters.Indeed, compare with the "modern" way of doing it:
https://github.com/commandlineparser/commandline/tree/master...
...or something slightly simpler (because it's only one file!):
https://github.com/mono/mono/blob/master/mcs/class/Mono.Opti...
It may seem like an exaggeration, but in my experience working with C# and Java, code like that is the norm --- the core functionality is obscured by being scattered amongst a large amount of "fluff" and it's hard to get the whole picture of how it works because the flow jumps around so much. In contrast, the C code in this article can be understood by just staring at it for a little bit --- the entire functionality is contained within less than a dozen lines.