aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-12-07 21:52:00 -0600
committerRob Landley <rob@landley.net>2016-12-07 21:52:00 -0600
commit0322afbc01cae09811a3f7b71088749100d2e6c9 (patch)
treec24ae5ba29b4888833ecc972f204276e950ff26a
parent382057f588fbf2c2f7950b85dd317721b8d04c07 (diff)
downloadtoybox-0322afbc01cae09811a3f7b71088749100d2e6c9.tar.gz
Bugfix: configuring out a longopt confused the option parsing.
(This made ls -l not work when LS_COLOR was off.)
-rw-r--r--scripts/mkflags.c38
1 files changed, 31 insertions, 7 deletions
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;