xref: /inferno-os/appl/cmd/tclsh.b (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1implement Tclsh;
2
3include "sys.m";
4	sys: Sys;
5
6include "draw.m";
7
8include "bufio.m";
9	bufmod : Bufio;
10Iobuf : import bufmod;
11
12include "tk.m";
13
14include "../lib/tcl.m";
15	tcl : Tcl_Core;
16
17Tclsh: module {
18	init:	fn(ctxt: ref Draw->Context, argv: list of string);
19};
20
21init(ctxt: ref Draw->Context, argv : list of string){
22	sys=load Sys Sys->PATH;
23	tcl=load Tcl_Core Tcl_Core->PATH;
24	if (tcl==nil){
25		sys->print("Cannot load Tcl (%r)\n");
26		exit;
27	}
28	bufmod=load Bufio Bufio->PATH;
29	if (bufmod==nil){
30		sys->print("Cannot load Bufio (%r)\n");
31		exit;
32	}
33	lines:=chan of string;
34	tcl->init(ctxt,argv);
35	new_inp := "tcl%";
36	spawn tcl->grab_lines(nil,nil,lines);
37	for(;;){
38		alt{
39			line := <-lines =>
40				line = tcl->prepass(line);
41				msg:= tcl->evalcmd(line,0);
42				if (msg!=nil)
43					sys->print("%s\n",msg);
44				sys->print("%s ", new_inp);
45				tcl->clear_error();
46		}
47	}
48}
49