blob: e47b7ed01cec934de22a71318050bfff4e63e4d4 (
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
|
implement Echo;
include "sys.m";
sys: Sys;
include "draw.m";
Echo: module
{
init: fn(nil: ref Draw->Context, nil: list of string);
};
init(nil: ref Draw->Context, args: list of string)
{
sys = load Sys Sys->PATH;
if(args != nil)
args = tl args;
addnl := 1;
if(args != nil && (hd args == "-n" || hd args == "--")) {
if(hd args == "-n")
addnl = 0;
args = tl args;
}
s := "";
if(args != nil) {
s = hd args;
while((args = tl args) != nil)
s += " " + hd args;
}
if(addnl)
s[len s] = '\n';
a := array of byte s;
if(sys->write(sys->fildes(1), a, len a) < 0){
sys->fprint(sys->fildes(2), "echo: write error: %r\n");
raise "fail:write error";
}
}
|