aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/getflags.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2009-08-14 20:38:22 -0700
committerRuss Cox <rsc@swtch.com>2009-08-14 20:38:22 -0700
commitae03a48ba93f8ccf98093105523897833c63029c (patch)
treee20de1127f799a1cf9236917064b420020343852 /src/cmd/getflags.c
parent5a8bc78967fef8f97da30b4368ca7e79dfdd274f (diff)
downloadplan9port-ae03a48ba93f8ccf98093105523897833c63029c.tar.gz
plan9port-ae03a48ba93f8ccf98093105523897833c63029c.tar.bz2
plan9port-ae03a48ba93f8ccf98093105523897833c63029c.zip
move files that codebot put in the wrong place
Diffstat (limited to 'src/cmd/getflags.c')
-rw-r--r--src/cmd/getflags.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/cmd/getflags.c b/src/cmd/getflags.c
new file mode 100644
index 00000000..bb0edf28
--- /dev/null
+++ b/src/cmd/getflags.c
@@ -0,0 +1,82 @@
+#include <u.h>
+#include <libc.h>
+
+void
+usage(void)
+{
+ print("status=usage\n");
+ exits(0);
+}
+
+char*
+findarg(char *flags, Rune r)
+{
+ char *p;
+ Rune rr;
+
+ for(p=flags; p!=(char*)1; p=strchr(p, ',')+1){
+ chartorune(&rr, p);
+ if(rr == r)
+ return p;
+ }
+ return nil;
+}
+
+int
+countargs(char *p)
+{
+ int n;
+
+ n = 1;
+ while(*p == ' ')
+ p++;
+ for(; *p && *p != ','; p++)
+ if(*p == ' ' && *(p-1) != ' ')
+ n++;
+ return n;
+}
+
+void
+main(int argc, char *argv[])
+{
+ char *flags, *p, buf[512];
+ int i, n;
+ Fmt fmt;
+
+ quotefmtinstall();
+ argv0 = argv[0]; /* for sysfatal */
+
+ flags = getenv("flagfmt");
+ if(flags == nil){
+ fprint(2, "$flagfmt not set\n");
+ print("exit 'missing flagfmt'");
+ exits(0);
+ }
+
+ fmtfdinit(&fmt, 1, buf, sizeof buf);
+ for(p=flags; p!=(char*)1; p=strchr(p, ',')+1)
+ fmtprint(&fmt, "flag%.1s=()\n", p);
+ ARGBEGIN{
+ default:
+ if((p = findarg(flags, ARGC())) == nil)
+ usage();
+ p += runelen(ARGC());
+ if(*p == ',' || *p == 0){
+ fmtprint(&fmt, "flag%C=1\n", ARGC());
+ break;
+ }
+ n = countargs(p);
+ fmtprint(&fmt, "flag%C=(", ARGC());
+ for(i=0; i<n; i++)
+ fmtprint(&fmt, "%s%q", i ? " " : "", EARGF(usage()));
+ fmtprint(&fmt, ")\n");
+ }ARGEND
+
+ fmtprint(&fmt, "*=(");
+ for(i=0; i<argc; i++)
+ fmtprint(&fmt, "%s%q", i ? " " : "", argv[i]);
+ fmtprint(&fmt, ")\n");
+ fmtprint(&fmt, "status=''\n");
+ fmtfdflush(&fmt);
+ exits(0);
+}