[Toybox] special options handling

Rob Landley rob at landley.net
Tue May 1 11:15:18 PDT 2012


On 05/01/2012 07:37 AM, Ashwini Sharma wrote:
> Hi Rob,
> 
> Is there any mechanism to handle special options.
> 
> By special options I mean, e.g in *fsck* *command* file-system specific
> options can be specified on command line.

If you put ? at the start of the NEWTOY option string you get unknown
arguments passed through to you, rather than erroring out on them. (And
in fact this had to distinguish "echo -n blah" from "echo -nx blah"
where the -nx had to print out. I got that working years ago.)

If all else fails, you can always bypass automated option parsing
completely by passing NULL as the option string in newtoy. So if you
really have to do it manually, you can.

(If you look at echo as an example of ? note that supplying ^ at the
start says to stop option parsing at the first non-option argument,
which is needed for "xargs -l 2 ls -l" and such. It's also something
echo needs, because "echo blah -n" and "echo -n blah" aren't supposed to
behave the same way. What really annoys me about echo is that it doesn't
understand -- so there's no way to go "echo $BLAH" _safely_, if $BLAH is
going to evaluate to "-e" then it gets interpreted rather than output.
Sure I could add -- support to the toybox version, it's actually the
default behavior although ?^ disables it, but no _other_ version of echo
does that...)

> But since we don't have any way to know all the options for a specific
> file-system checker, we can't mention them in the NEWTOY macro.
> Can you please point me in right direction, on how to handle this.?

Sounds like you want ? to pass through unknown options.

Rob
-- 
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
Either it's "mere aggregation", or a license violation.  Pick one.

 1335896118.0


More information about the Toybox mailing list