aux/getflags: fix named rune arguments.

Flags can be runes. That means that we can't just
look at p[1] to decide if we have a named argument,
we need to look one rune forward. This change
does that.
This commit is contained in:
Ori Bernstein 2020-06-04 11:41:03 -07:00
parent 5f3e72eb84
commit 2327b48d77

View file

@ -76,6 +76,7 @@ main(int argc, char *argv[])
{
char *flags, *p, *s, *e, buf[512];
int i, n;
Rune r;
Fmt fmt;
doquote = needsrcquote;
@ -92,14 +93,15 @@ main(int argc, char *argv[])
fmtfdinit(&fmt, 1, buf, sizeof buf);
for(p=skipspace(flags); *p; p=nextarg(p)){
s = e = nil;
if(p[1] == ':'){
s = p + 2;
n = chartorune(&r, p);
if(p[n] == ':'){
s = p + n + 1;
e = argname(s);
}
if(s != e)
fmtprint(&fmt, "%.*s=()\n", (int)(e - s), s);
else
fmtprint(&fmt, "flag%.1s=()\n", p);
fmtprint(&fmt, "flag%C=()\n", r);
}
ARGBEGIN{
default: