* aux/getflags: name the flags
@ 2020-04-17 21:11 ori
2020-04-18 16:22 ` [9front] " cinap_lenrek
0 siblings, 1 reply; 3+ messages in thread
From: ori @ 2020-04-17 21:11 UTC (permalink / raw)
To: 9front
I dislike using aux/getflags, because the flag
names aren't under my control. So I patched it:
% flagfmt='b:bullshit,s:stuff,f:dobinary binary,r res,x width'
% 6.getflags -bsflags and some args
bullshit=()
stuff=()
dobinary=()
flagr=()
flagx=()
bullshit=1
stuff=1
dobinary=(lags)
*=(and some args)
status=''
I'm not sure if this should be committed -- but the code is here:
diff -r 247ac32522a0 sys/src/cmd/aux/getflags.c
--- a/sys/src/cmd/aux/getflags.c Wed Apr 15 18:16:22 2020 +0200
+++ b/sys/src/cmd/aux/getflags.c Fri Apr 17 14:10:28 2020 -0700
@@ -1,5 +1,6 @@
#include <u.h>
#include <libc.h>
+#include <ctype.h>
void
usage(void)
@@ -22,6 +23,21 @@
return nil;
}
+char*
+argname(char *p)
+{
+ Rune r;
+ int n;
+
+ while(1){
+ n = chartorune(&r, p);
+ if(!isalpharune(r) && !isdigitrune(r))
+ break;
+ p += n;
+ }
+ return p;
+}
+
int
countargs(char *p)
{
@@ -39,7 +55,7 @@
void
main(int argc, char *argv[])
{
- char *flags, *p, buf[512];
+ char *flags, *p, *s, *e, buf[512];
int i, n;
Fmt fmt;
@@ -55,19 +71,38 @@
}
fmtfdinit(&fmt, 1, buf, sizeof buf);
- for(p=flags; p!=(char*)1; p=strchr(p, ',')+1)
- fmtprint(&fmt, "flag%.1s=()\n", p);
+ for(p=flags; p!=(char*)1 && *p != 0; p=strchr(p, ',')+1){
+ s = e = nil;
+ if(p[1] == ':'){
+ s = p + 2;
+ e = argname(s);
+ }
+ if(s != e)
+ fmtprint(&fmt, "%.*s=()\n", (int)(e - s), s);
+ else
+ fmtprint(&fmt, "flag%.1s=()\n", p);
+ }
ARGBEGIN{
default:
if((p = findarg(flags, ARGC())) == nil)
usage();
p += runelen(ARGC());
+ s = p + 1;
+ e = p + 1;
+ if(*p == ':' && (e = argname(s)) != s)
+ p = e;
if(*p == ',' || *p == 0){
- fmtprint(&fmt, "flag%C=1\n", ARGC());
+ if(s != e)
+ fmtprint(&fmt, "%.*s=1\n", (int)(e - s), s);
+ else
+ fmtprint(&fmt, "flag%C=1\n", ARGC());
break;
}
n = countargs(p);
- fmtprint(&fmt, "flag%C=(", ARGC());
+ if(s != e)
+ fmtprint(&fmt, "%.*s=(", (int)(e - s), s);
+ else
+ fmtprint(&fmt, "flag%C=(", ARGC());
for(i=0; i<n; i++)
fmtprint(&fmt, "%s%q", i ? " " : "", EARGF(usage()));
fmtprint(&fmt, ")\n");
diff -r 247ac32522a0 sys/src/cmd/aux/usage.c
--- a/sys/src/cmd/aux/usage.c Wed Apr 15 18:16:22 2020 +0200
+++ b/sys/src/cmd/aux/usage.c Fri Apr 17 14:10:28 2020 -0700
@@ -31,6 +31,9 @@
single = 0;
for(p=flags; *p; ){
p += chartorune(&r, p);
+ if(*p == ':')
+ while(*p != '\0' && *p != ',' && *p != ' ')
+ p++;
if(*p == ',' || *p == 0){
if(!single){
fmtprint(&fmt, " [-");
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] aux/getflags: name the flags
2020-04-17 21:11 aux/getflags: name the flags ori
@ 2020-04-18 16:22 ` cinap_lenrek
2020-04-18 18:24 ` ori
0 siblings, 1 reply; 3+ messages in thread
From: cinap_lenrek @ 2020-04-18 16:22 UTC (permalink / raw)
To: 9front
I'm not sure if this should be committed -- but the code is here.
why would it not be commited? i think this makes alot of sense and
is a good addition.
but please provide the documentation for the manpage.
--
cinap
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] aux/getflags: name the flags
2020-04-18 16:22 ` [9front] " cinap_lenrek
@ 2020-04-18 18:24 ` ori
0 siblings, 0 replies; 3+ messages in thread
From: ori @ 2020-04-18 18:24 UTC (permalink / raw)
To: cinap_lenrek, 9front
> why would it not be commited? i think this makes alot of sense and
> is a good addition.
Because now I'm tempted to add other things like manatory/optional
arguments; I don't know how much I want to bloat this.
But, yep -- will add docs, and then commit.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-18 18:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17 21:11 aux/getflags: name the flags ori
2020-04-18 16:22 ` [9front] " cinap_lenrek
2020-04-18 18:24 ` 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).