From 52bbc1e0a410b44a926b04aaae3b00f9f50da81e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 14 Nov 2020 23:39:18 -0600 Subject: Allow 0 prefix to optstr to include argv[0] in optargs[0]. --- scripts/mkflags.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'scripts/mkflags.c') 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])) { -- cgit v1.2.3