diff options
author | Rob Landley <rob@landley.net> | 2020-11-14 23:39:18 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-11-14 23:39:18 -0600 |
commit | 52bbc1e0a410b44a926b04aaae3b00f9f50da81e (patch) | |
tree | a909959953794b6faafc2731b1bcccfbb5faf941 /scripts | |
parent | 3e28f611e452b52b21360c56dbf250d242bbb4a5 (diff) | |
download | toybox-52bbc1e0a410b44a926b04aaae3b00f9f50da81e.tar.gz |
Allow 0 prefix to optstr to include argv[0] in optargs[0].
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/mkflags.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/scripts/mkflags.c b/scripts/mkflags.c index fff9dd4c..7ea8770d 100644 --- a/scripts/mkflags.c +++ b/scripts/mkflags.c @@ -22,21 +22,23 @@ struct flag { int chrtype(char c) { // Does this populate a GLOBALS() variable? - if (strchr("?&^-:#|@*; %", c)) return 1; + if (strchr("^-:#|@*; %.", c)) return 1; // Is this followed by a numeric argument in optstr? if (strchr("=<>", c)) return 2; + if (strchr("?&0", c)) return 3; + return 0; } // replace chopped out USE_BLAH() sections with low-ascii characters -// showing how many flags got skipped +// showing how many flags got skipped so FLAG_ macros stay constant char *mark_gaps(char *flags, char *all) { char *n, *new, c; - int bare = 1; + int bare = 2; // Shell feeds in " " for blank args, leading space not meaningful. while (isspace(*flags)) flags++; @@ -48,7 +50,8 @@ char *mark_gaps(char *flags, char *all) if (*all == '(') { int len = 0; - while (all[len++] != ')'); + if (bare) bare = 1; + while (all[len]) if (all[len++] == ')') break; if (strncmp(flags, all, len)) { // bare longopts need their own skip placeholders if (bare) *(new++) = 1; @@ -61,7 +64,7 @@ char *mark_gaps(char *flags, char *all) continue; } c = *(all++); - if (bare) bare = chrtype(c); + if (bare && !chrtype(c)) bare = 0; if (*flags == c) { *(new++) = c; flags++; @@ -69,7 +72,7 @@ char *mark_gaps(char *flags, char *all) } c = chrtype(c); - if (!c) *(new++) = 1; + if (!c || (!bare && c==3)) *(new++) = 1; else if (c==2) while (isdigit(*all)) all++; } *new = 0; @@ -81,7 +84,7 @@ char *mark_gaps(char *flags, char *all) struct flag *digest(char *string) { - struct flag *list = NULL; + struct flag *list = 0; char *err = string, c; while (*string) { @@ -112,7 +115,7 @@ struct flag *digest(char *string) } c = chrtype(*string); - if (c == 1) string++; + if (c == 1 || (c == 3 && !list)) string++; else if (c == 2) { if (string[1]=='-') string++; if (!isdigit(string[1])) { |