summaryrefslogtreecommitdiff
path: root/appl/alphabet/main/create.b
diff options
context:
space:
mode:
Diffstat (limited to 'appl/alphabet/main/create.b')
-rw-r--r--appl/alphabet/main/create.b55
1 files changed, 55 insertions, 0 deletions
diff --git a/appl/alphabet/main/create.b b/appl/alphabet/main/create.b
new file mode 100644
index 00000000..bb1601dc
--- /dev/null
+++ b/appl/alphabet/main/create.b
@@ -0,0 +1,55 @@
+implement Create,Mainmodule;
+include "sys.m";
+ sys: Sys;
+include "draw.m";
+include "sh.m";
+include "alphabet/reports.m";
+ reports: Reports;
+ Report, report: import reports;
+include "alphabet.m";
+ alphabet: Alphabet;
+ Value: import alphabet;
+
+Create: module {};
+
+typesig(): string
+{
+ return "rfs";
+}
+
+init()
+{
+ sys = load Sys Sys->PATH;
+ alphabet = load Alphabet Alphabet->PATH;
+ reports = load Reports Reports->PATH;
+}
+
+quit()
+{
+}
+
+run(nil: ref Draw->Context, nil: ref Reports->Report, errorc: chan of string,
+ nil: list of (int, list of ref Alphabet->Value),
+ args: list of ref Alphabet->Value): ref Alphabet->Value
+{
+ r := chan of string;
+ fd := sys->create((hd tl args).s().i, Sys->OWRITE, 8r666);
+ if(fd == nil){
+ report(errorc, sys->sprint("error: cannot create %q: %r", (hd tl args).s().i));
+ return nil;
+ }
+ spawn createproc(r, (hd args).f().i, fd);
+ return ref Value.Vr(r);
+}
+
+createproc(r: chan of string, f: chan of ref Sys->FD, fd: ref Sys->FD)
+{
+ if(<-r != nil){
+ <-f;
+ f <-= nil;
+ exit;
+ }
+ <-f;
+ f <-= fd;
+ r <-= nil;
+}