diff options
| author | Charles.Forsyth <devnull@localhost> | 2007-03-12 10:14:58 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2007-03-12 10:14:58 +0000 |
| commit | 3555c65fdd2b7ff06f1847e174486888d459748c (patch) | |
| tree | b1ee7f5be6eb6d3e6f452cb542f29086af589c37 | |
| parent | afa0750d508628e0f365b66668effa26b1c8d8a2 (diff) | |
"20070312a plumb -i"
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | appl/cmd/plumb.b | 85 | ||||
| -rw-r--r-- | dis/plumb.dis | bin | 2015 -> 2375 bytes | |||
| -rw-r--r-- | include/version.h | 2 | ||||
| -rw-r--r-- | man/1/plumb | 30 |
5 files changed, 74 insertions, 45 deletions
@@ -1,3 +1,5 @@ +20070312 + rename -D and -k options to plumb (old ones still accepted); add -i option to take data from standard input; update man page 20070302 change /mkfile to build yacc earlier, mainly to make bootstrap of a new host easier (makemk.sh and mk install) change /utils/mkfile not to build k[acl] and q[acl] on Plan 9, since the system ones are the same diff --git a/appl/cmd/plumb.b b/appl/cmd/plumb.b index 88879715..2e4d3af3 100644 --- a/appl/cmd/plumb.b +++ b/appl/cmd/plumb.b @@ -6,7 +6,6 @@ include "sys.m"; include "draw.m"; include "arg.m"; - arg: Arg; include "plumbmsg.m"; plumbmsg: Plumbmsg; @@ -20,18 +19,9 @@ Plumb: module init: fn(nil: ref Draw->Context, nil: list of string); }; -usage() -{ - sys->fprint(stderr(), "Usage: plumb [-s src] [-d dest] [-D dir] [-k kind] [-a name val] ... data ...\n"); - raise "fail:usage"; -} - init(nil: ref Draw->Context, args: list of string) { sys = load Sys Sys->PATH; - arg = load Arg Arg->PATH; - if(arg == nil) - nomod(Arg->PATH); plumbmsg = load Plumbmsg Plumbmsg->PATH; if(plumbmsg == nil) nomod(Plumbmsg->PATH); @@ -43,28 +33,46 @@ init(nil: ref Draw->Context, args: list of string) err(sys->sprint("can't connect to plumb: %r")); attrs: list of ref Attr; + input := 0; m := ref Msg("plumb", nil, workdir->init(), "text", nil, nil); + arg := load Arg Arg->PATH; arg->init(args); + arg->setusage("plumb [-s src] [-d dest] [-w wdir] [-t type] [-a name val] -i | ... data ..."); while((c := arg->opt()) != 0) case c { 's' => - m.src = use(arg->arg(), c); + m.src = arg->earg(); 'd' => - m.dst = use(arg->arg(), c); - 'D' => - m.dir = use(arg->arg(), c); - 'k' => - m.kind = use(arg->arg(), c); + m.dst = arg->earg(); + 'w' or 'D' => + m.dir = arg->earg(); + 'i' => + input++; + 't' or 'k'=> + m.kind = arg->arg(); 'a' => - name := use(arg->arg(), c); - val := use(arg->arg(), c); + name := arg->earg(); + val := arg->earg(); attrs = tack(attrs, ref Attr(name, val)); * => - usage(); + arg->usage(); } args = arg->argv(); - if(args == nil) - usage(); + if(input && args != nil || !input && args == nil) + arg->usage(); + arg = nil; + + if(input){ + m.data = gather(sys->fildes(0)); + (notfound, nil) := plumbmsg->lookup(plumbmsg->string2attrs(m.attr), "action"); + if(notfound) + tack(attrs, ref Attr("action", "showdata")); + m.attr = plumbmsg->attrs2string(attrs); + if(m.send() < 0) + err(sys->sprint("can't send message: %r")); + exit; + } + nb := 0; for(a := args; a != nil; a = tl a) nb += len array of byte hd a; @@ -83,6 +91,24 @@ init(nil: ref Draw->Context, args: list of string) err(sys->sprint("can't plumb message: %r")); } +gather(fd: ref Sys->FD): array of byte +{ + Chunk: con 8192; # arbitrary + ndata := 0; + buf := array[Chunk] of byte; + while((n := sys->read(fd, buf[ndata:], len buf - ndata)) > 0){ + ndata += n; + if(len buf - ndata < Chunk){ + t := array[len buf+Chunk] of byte; + t[0:] = buf[0: ndata]; + buf = t; + } + } + if(n < 0) + err(sys->sprint("error reading input: %r")); + return buf[0: ndata]; +} + tack(l: list of ref Attr, v: ref Attr): list of ref Attr { if(l == nil) @@ -90,26 +116,13 @@ tack(l: list of ref Attr, v: ref Attr): list of ref Attr return hd l :: tack(tl l, v); } -use(s: string, c: int): string -{ - if(s == nil) - err(sys->sprint("missing value for -%c", c)); - return s; -} - nomod(m: string) { - err(sys->sprint("can't load %s: %r\n", m)); + err(sys->sprint("can't load %s: %r", m)); } err(s: string) { - sys->fprint(stderr(), "plumb: %s\n", s); + sys->fprint(sys->fildes(2), "plumb: %s\n", s); raise "fail:error"; } - -stderr(): ref Sys->FD -{ - return sys->fildes(2); -} - diff --git a/dis/plumb.dis b/dis/plumb.dis Binary files differindex 8080303f..2430bc09 100644 --- a/dis/plumb.dis +++ b/dis/plumb.dis diff --git a/include/version.h b/include/version.h index 7c30efaf..224f2d4f 100644 --- a/include/version.h +++ b/include/version.h @@ -1 +1 @@ -#define VERSION "Fourth Edition (20070302)" +#define VERSION "Fourth Edition (20070312)" diff --git a/man/1/plumb b/man/1/plumb index 350c472c..1fa93544 100644 --- a/man/1/plumb +++ b/man/1/plumb @@ -8,11 +8,13 @@ plumb \- send message to plumber ] [ .BI -d " dest" ] [ -.BI -D " dir" +.BI -w " wdir" ] [ -.BI -k " kind" +.BI -t " type" ] [ .BI -a " name value" +] [ +.B -i ] .I data \&... @@ -40,17 +42,17 @@ Set the destination to .I dest (default: unspecified). .TP -.BI -D " dir" -Set the directory to -.I dir +.BI -w " wdir" +Set the working directory to +.I wdir (default: current directory as reported by .IR pwd (1) or .IR workdir (2)). .TP -.BI -k " kind" -Set the kind of data to -.I kind +.BI -t " type" +Set the type of data to +.I type (default: .BR text ) .TP @@ -58,6 +60,18 @@ Set the kind of data to Include an attribute .RI ` name = value '; there can be more than one. +.TP +.B -i +Take the +.I data +from the standard input not from the argument strings. +If an +.B action +attribute is not otherwise specified, +.I plumb +will add an +.B action=showdata +attribute to the message. .PP The remaining arguments are sent, separated by spaces, as the .I data |
