[Toybox] long opts
Rob Landley
rob at landley.net
Mon Apr 29 10:45:49 PDT 2013
On 04/29/2013 12:05:51 AM, Ashwini Sharma wrote:
> Hi Rob,
>
> Are the long options handled completely at present?
>
> I think the long options are not handled if they don't have a
> corresponding
> short-option.
I believe they're handled, but scripts/make.sh doesn't create a FLAG_x
value for them in generated/globals.h.
What I need to do is create FLAG_longname macros for each longopt, I
just haven't gotten around to it yet.
(Today I'm taking a day off from work to respond to the 3.9 kernel
release, and this is letting me catch up on all sorts of pending todo
items...)
> Whats your opinion and do you have any design or plan to get this
> feature
> in.
The plan is that you list longopts with no corresponding short option
first, before any short options. That way each one allocates its own
unique bit out of optflags. I think lib/args.c is doing it right, but I
haven't written the scripts/make.sh plumbing to generate longopt
#defines yet so you can't tell what the flag values are unless you
calculate them by hand.
Let's see, quick and dirty:
--- a/toys/other/hello.c Mon Apr 29 12:30:28 2013 -0500
+++ b/toys/other/hello.c Mon Apr 29 12:39:43 2013 -0500
@@ -5,7 +5,7 @@
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
* See
http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
-USE_HELLO(NEWTOY(hello, "e at d*c#b:a", TOYFLAG_USR|TOYFLAG_BIN))
+USE_HELLO(NEWTOY(hello, "(walrus)(blubber)e at d*c#b:a",
TOYFLAG_USR|TOYFLAG_BIN))
config HELLO
bool "hello"
@@ -35,7 +35,7 @@
void hello_main(void)
{
- printf("Hello world\n");
+ printf("Hello world %x\n", toys.optflags);
if (toys.optflags & FLAG_a) printf("Saw a\n");
if (toys.optflags & FLAG_b) printf("b=%s\n", TT.b_string);
Hmmm, and both "./hello --walrus" and "./hello --blubber" say 0x20. So
the lib/args.c plumbing does need a fixup to advance to the next bit
when we're not attaching a longopt to a shortopt. (It's betting
--blubber right in bit position 6, but --walrus should be bit position
_7_, I.E. 0x40.)
Ordinarily if you go "a(long1)(long2)" both long options are aliases of
the short option they're attached to, but when a long option is_not_
attached to a short option it should get a unique bit. Right now it's
only doing that for the first longoption that's not attached to a short
options, the others alias to that first longopt. Oops.
So yeah, I've got some work to do here. I'll try to tackle it today but
I really need to get my devtmpfs patch submitted to the linux 3.10
merge window, test linux 3.9 in aboriginal on all targets (just fixed
up the patches to apply to the new kernel, it's test building x86-64
now), and track down a bug that happens under Centos 6.4.
> -Ashwini
Rob
More information about the Toybox
mailing list