summaryrefslogtreecommitdiff
path: root/appl/alphabet/main/print.b
blob: 1232793435bbf5d5b7225c450f720426909d73e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
implement Print,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;

Print: 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->fildes(int (hd tl args).s().i);
	if(fd == nil){
		report(errorc, sys->sprint("error: no such fd %q", (hd tl args).s().i));
		return nil;
	}
	spawn printproc(r, (hd args).f().i, fd);
	return ref Value.Vr(r);
}

printproc(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;
}