From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from yow.a-b.xyz ([45.32.152.219]) by ewsd; Tue May 5 22:52:35 EDT 2020 Received: by yow.a-b.xyz (OpenSMTPD) with ESMTPSA id 1684880f (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Wed, 6 May 2020 04:52:21 +0200 (CEST) Message-ID: To: 9front@9front.org Subject: [PATCH] aux/getflags improvements Date: Wed, 6 May 2020 04:52:21 +0200 From: kvik@a-b.xyz MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: mobile compliant dependency wrapper database This makes flagfmt= parser more admitting and convenient to use. Any number of commas and newlines as well as any whitespace is eaten as a specifier separator. This makes it so that a possibly long flagfmt can be broken up, like this: flagfmt=' a:all, b, 9, f:files f1 f2' Is this worth a mention in the manpage? Does this look alright to commit? diff -r 0ee17db5d86b sys/src/cmd/aux/getflags.c --- a/sys/src/cmd/aux/getflags.c Sat May 02 17:32:01 2020 +0200 +++ b/sys/src/cmd/aux/getflags.c Wed May 06 04:23:15 2020 +0200 @@ -9,18 +9,34 @@ exits(0); } +#define issep(c) ((c) == ',' || (c) == '\n') + +char* +nextarg(char *p) +{ + p = strpbrk(p, ",\n"); + if(p == nil) + return nil; + while(issep(*p) || isspace(*p)) + p++; + return p; +} + char* findarg(char *flags, Rune r) { char *p; Rune rr; - - for(p=flags; p!=(char*)1; p=strchr(p, ',')+1){ + + p = flags; + while(isspace(*p)) + p++; + for(; p && *p; p=nextarg(p)){ chartorune(&rr, p); if(rr == r) return p; } - return nil; + return nil; } char* @@ -44,9 +60,9 @@ int n; n = 1; - while(*p == ' ') + while(p && *p == ' ') p++; - for(; *p && *p != ','; p++) + for(; p && *p && !issep(*p); p++) if(*p == ' ' && *(p-1) != ' ') n++; return n; @@ -71,7 +87,10 @@ } fmtfdinit(&fmt, 1, buf, sizeof buf); - for(p=flags; p!=(char*)1 && *p != 0; p=strchr(p, ',')+1){ + p = flags; + while(isspace(*p)) + p++; + for(; p && *p; p=nextarg(p)){ s = e = nil; if(p[1] == ':'){ s = p + 2; @@ -91,7 +110,7 @@ e = p + 1; if(*p == ':' && (e = argname(s)) != s) p = e; - if(*p == ',' || *p == 0){ + if(issep(*p) || *p == 0){ if(s != e) fmtprint(&fmt, "%.*s=1\n", (int)(e - s), s); else