9front - general discussion about 9front
 help / color / mirror / Atom feed
* [PATCH] aux/getflags improvements
@ 2020-05-06  2:52 kvik
  2020-05-06  2:57 ` [9front] " ori
  0 siblings, 1 reply; 2+ messages in thread
From: kvik @ 2020-05-06  2:52 UTC (permalink / raw)
  To: 9front

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] [PATCH] aux/getflags improvements
  2020-05-06  2:52 [PATCH] aux/getflags improvements kvik
@ 2020-05-06  2:57 ` ori
  0 siblings, 0 replies; 2+ messages in thread
From: ori @ 2020-05-06  2:57 UTC (permalink / raw)
  To: kvik, 9front

> 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?

Yes.
 
> Does this look alright to commit?

You'll need a corresponding change in aux/usage.

I also mildly prefer making '\n' equivalent to ' ' rather
than ',', but I'm not going to bikeshed that.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-06  2:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06  2:52 [PATCH] aux/getflags improvements kvik
2020-05-06  2:57 ` [9front] " ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).