summaryrefslogtreecommitdiff
path: root/appl/cmd/echo.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/echo.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/cmd/echo.b')
-rw-r--r--appl/cmd/echo.b36
1 files changed, 36 insertions, 0 deletions
diff --git a/appl/cmd/echo.b b/appl/cmd/echo.b
new file mode 100644
index 00000000..e47b7ed0
--- /dev/null
+++ b/appl/cmd/echo.b
@@ -0,0 +1,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";
+ }
+}