summaryrefslogtreecommitdiff
path: root/appl/cmd/fs/select.b
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/fs/select.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/cmd/fs/select.b')
-rw-r--r--appl/cmd/fs/select.b56
1 files changed, 56 insertions, 0 deletions
diff --git a/appl/cmd/fs/select.b b/appl/cmd/fs/select.b
new file mode 100644
index 00000000..9fe5e4b0
--- /dev/null
+++ b/appl/cmd/fs/select.b
@@ -0,0 +1,56 @@
+implement Fsmodule;
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "sh.m";
+include "fslib.m";
+ fslib: Fslib;
+ Report, Value, type2s, quit: import fslib;
+ Fschan, Fsdata, Entrychan, Entry,
+ Gatechan, Gatequery, Nilentry, Option,
+ Next, Down, Skip, Quit: import Fslib;
+
+types(): string
+{
+ return "tpt";
+}
+
+badmod(p: string)
+{
+ sys->fprint(sys->fildes(2), "fs: size: cannot load %s: %r\n", p);
+ raise "fail:bad module";
+}
+
+init()
+{
+ sys = load Sys Sys->PATH;
+ fslib = load Fslib Fslib->PATH;
+ if(fslib == nil)
+ badmod(Fslib->PATH);
+}
+
+run(nil: ref Draw->Context, nil: ref Report,
+ nil: list of Option, args: list of ref Value): ref Value
+{
+ dst := Entrychan(chan of int, chan of Entry);
+ spawn selectproc((hd tl args).t().i, dst, (hd args).p().i);
+ return ref Value.T(dst);
+}
+
+selectproc(src, dst: Entrychan, query: Gatechan)
+{
+ if(<-dst.sync == 0){
+ query <-= (Nilentry, nil);
+ src.sync <-= 0;
+ exit;
+ }
+ src.sync <-= 1;
+ reply := chan of int;
+ while((d := <-src.c).t0 != nil){
+ query <-= (d, reply);
+ if(<-reply)
+ dst.c <-= d;
+ }
+ dst.c <-= Nilentry;
+ query <-= (Nilentry, nil);
+}