From 0322afbc01cae09811a3f7b71088749100d2e6c9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 7 Dec 2016 21:52:00 -0600 Subject: Bugfix: configuring out a longopt confused the option parsing. (This made ls -l not work when LS_COLOR was off.) --- scripts/mkflags.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'scripts/mkflags.c') diff --git a/scripts/mkflags.c b/scripts/mkflags.c index 39b935bb..c263e31f 100644 --- a/scripts/mkflags.c +++ b/scripts/mkflags.c @@ -19,12 +19,21 @@ struct flag { struct flag *lopt; }; +int chrtype(char c) +{ + if (strchr("?&^-:#|@*; ", c)) return 1; + if (strchr("=<>", c)) return 2; + + return 0; +} + // replace chopped out USE_BLAH() sections with low-ascii characters // showing how many flags got skipped char *mark_gaps(char *flags, char *all) { char *n, *new, c; + int bare = 1; // Shell feeds in " " for blank args, leading space not meaningful. while (isspace(*flags)) flags++; @@ -32,17 +41,32 @@ char *mark_gaps(char *flags, char *all) n = new = strdup(all); while (*all) { - if (*flags == *all) { - *(new++) = *(all++); + // --longopt parentheticals dealt with as a unit + if (*all == '(') { + int len = 0; + + while (all[len++] != ')'); + if (strncmp(flags, all, len)) { + // bare longopts need their own skip placeholders + if (bare) *(new++) = 1; + } else { + memcpy(new, all, len); + new += len; + flags += len; + } + all += len; + } + c = *(all++); + if (bare) bare = chrtype(c); + if (*flags == c) { + *(new++) = c; *flags++; continue; } - c = *(all++); - if (strchr("?&^-:#|@*; ", c)); - else if (strchr("=<>", c)) while (isdigit(*all)) all++; - else if (c == '(') while(*(all++) != ')'); - else *(new++) = 1; + c = chrtype(c); + if (!c) *(new++) = 1; + else if (c==2) while (isdigit(*all)) all++; } *new = 0; -- cgit v1.2.3