[BusyBox] calling getopt() centrally

Bob Tinsley bob at earthrise.demon.co.uk
Thu Dec 19 07:08:03 UTC 2002


From: "Vladimir N. Oleynik" <dzo at simtreas.ru>
> Please change
> applet_opts[opt] = (void *) ~0; 
> to
> applet_opts[opt] = NULL;
> for next correct compare.

The idea is that applet_opts['a'] is NULL if the -a switch isn't given,
and non-NULL if the -a switch is given. If -a takes an argument, then
applet_opts['a'] is a pointer to it.

In other words, this assignment has to be to anything other than NULL.

> Also, may be changing void * to char * for applet_opts.

Sounds good. Also, we only really need to allow 65-122 ('A' to 'z')
as options rather than 0-127 so we can make the malloc much smaller.

> You can apply your idea without rewrote optind -> argn, 
> your algorithm equivalent set optind ;)

To be honest, it seems to me much cleaner to simplify the code and
just drop optind altogether from the applets if they don't need it.

> Also, may be creating two new macros for applets.h 
> with and without your global getopt (NULL and not null arg)?

I thought about this, but I'm not sure it really offers us anything
and adding another argument to the existing macros makes it
more obvious what is happening.

applets.h is already a big macro-soup and I wouldn't like to
see it get any worse.

> My idea:
[snip]

Looks interesting, but I'm not clear what it would gain us.

Cheers,

bob






More information about the busybox mailing list