[Toybox] Subject: [PATCH] Add getopt(1).
Rob Landley
rob at landley.net
Sun Nov 24 01:17:43 PST 2019
On 11/23/19 10:18 AM, enh wrote:
> The only real point of getopt(1) over the getopts built-in is long options.
> That's all I've seen it used for in practice. It does seem like folks know about
> getopts, and they do use it when short options are all they want.
The reason it was still on my todo list is I wanted to write one that satisfied
both groups of users, worked nicely as a shell builtin, and either used the
lib/args.c plumbing or did it in the command.
My main _handicap_ here is I never used getopt or getopts because I've never
understood how either is supposed to _help_. (It's easier to just do it by hand.
My first couple hours of research didn't make it clearer to me why anyone would
use either, but clearly they do...)
However, getopts is all about setting environment variables, which means it can
only be implemented as a shell builtin, so I still have to write a getopts for
toysh, and now we've got two that don't share code.
And reading man 1 getopt spends an inordinate amount of time talking about OTHER
VERSIONS of getopt (not getopts), and what it is or isn't compatible with, and
to be honest this entire area seems kind of horrific...
(Jello-brain aside, I'm currently got a huge toysh diff implementing variable
logic I need to reverse engineer enough to finish and apply, and I've got a
bunch of tabs open refamiliarizing myself with what tcgetattr() and setsid() and
such do for -i and job control and such, so not likely to open the getopts can
of worms on top of it just now. But this also makes me reluctant to promote
_this_ out of pending either.)
> While it was on my todo list for toysh, I'm not sure swallowing a large lump of
> gnu/glibc bespoke nonsense actually helps advance this ball. (Although I assume
> bionic copied an implementation from netbsd?)
>
> Correct. Apple's libc did too, so the getopt tests pass there too --- I tested
> yesterday when I was going through all the macos_defconfig tests.
"There are two versions of this plumbing in libc, which exist because each
didn't do what the other wanted, and I"m not currently using either because they
don't do what I want either". It's ftw.h all over again...
Rob
More information about the Toybox
mailing list