diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/export.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/cmd/export.b')
| -rw-r--r-- | appl/cmd/export.b | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/appl/cmd/export.b b/appl/cmd/export.b new file mode 100644 index 00000000..f6688fd3 --- /dev/null +++ b/appl/cmd/export.b @@ -0,0 +1,57 @@ +# +# export current name space on a connection +# + +implement Export; + +include "sys.m"; + sys: Sys; +include "draw.m"; + +Export: module +{ + init: fn(nil: ref Draw->Context, argv: list of string); +}; + +usage() +{ + sys->fprint(stderr(), "Usage: export [-a] dir [connection]\n"); + raise "fail:usage"; +} + +init(nil: ref Draw->Context, argv: list of string) +{ + # usage: export dir [connection] + sys = load Sys Sys->PATH; + if(argv != nil) + argv = tl argv; + flag := Sys->EXPWAIT; + for(; argv != nil && len hd argv && (hd argv)[0] == '-'; argv = tl argv) + for(i := 1; i < len hd argv; i++) + case (hd argv)[i] { + 'a' => + flag = Sys->EXPASYNC; + * => + usage(); + } + n := len argv; + if (n < 1 || n > 2) + usage(); + fd: ref Sys->FD; + if (n == 2) { + if ((fd = sys->open(hd tl argv, Sys->ORDWR)) == nil) { + sys->fprint(stderr(), "export: can't open %s: %r\n", hd tl argv); + raise "fail:open"; + } + } else + fd = sys->fildes(0); + if (sys->export(fd, hd argv, flag) < 0) { + sys->fprint(stderr(), "export: can't export: %r\n"); + raise "fail:export"; + } +} + +stderr(): ref Sys->FD +{ + return sys->fildes(2); +} |
