diff options
author | rsc <devnull@localhost> | 2005-02-11 19:44:04 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-02-11 19:44:04 +0000 |
commit | 276bf4edf1829a03198b9b35152af35eacf51061 (patch) | |
tree | 780e20bd3571b60e0ee831711e1a764d0b3c2daf /src/cmd/9p.c | |
parent | 83c4506aa5241351323a62b8fdee825058286f20 (diff) | |
download | plan9port-276bf4edf1829a03198b9b35152af35eacf51061.tar.gz plan9port-276bf4edf1829a03198b9b35152af35eacf51061.tar.bz2 plan9port-276bf4edf1829a03198b9b35152af35eacf51061.zip |
add write -l
Diffstat (limited to 'src/cmd/9p.c')
-rw-r--r-- | src/cmd/9p.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/cmd/9p.c b/src/cmd/9p.c index 2f76963c..b4ebade4 100644 --- a/src/cmd/9p.c +++ b/src/cmd/9p.c @@ -1,6 +1,7 @@ #include <u.h> #include <signal.h> #include <libc.h> +#include <bio.h> #include <fcall.h> #include <9pclient.h> #include <auth.h> @@ -15,7 +16,7 @@ usage(void) fprint(2, "possible cmds:\n"); fprint(2, " read name\n"); fprint(2, " readfd name\n"); - fprint(2, " write name\n"); + fprint(2, " write [-l] name\n"); fprint(2, " writefd name\n"); fprint(2, " stat name\n"); // fprint(2, " ls name\n"); @@ -176,8 +177,14 @@ xwrite(int argc, char **argv) char buf[1024]; int n, did; CFid *fid; + Biobuf *b; + char *p; + int byline; + byline = 0; ARGBEGIN{ + case 'l': + byline = 1; default: usage(); }ARGEND @@ -187,10 +194,25 @@ xwrite(int argc, char **argv) did = 0; fid = xopen(argv[0], OWRITE|OTRUNC); - while((n = read(0, buf, sizeof buf)) > 0){ - did = 1; - if(fswrite(fid, buf, n) != n) - sysfatal("write error: %r"); + if(byline){ + n = 0; + b = malloc(sizeof *b); + if(b == nil) + sysfatal("out of memory"); + Binit(b, 0, OREAD); + while((p = Brdstr(b, '\n', 0)) != nil){ + n = strlen(p); + did = 1; + if(fswrite(fid, p, n) != n) + sysfatal("write error: %r"); + } + free(b); + }else{ + while((n = read(0, buf, sizeof buf)) > 0){ + did = 1; + if(fswrite(fid, buf, n) != n) + sysfatal("write error: %r"); + } } if(n == 0 && !did){ if(fswrite(fid, buf, 0) != 0) |