
FUNCTION interpret(text) {
	status (text)

	k = index(text, " ")
	key = (k != 0)? substr(text, 1, k - 1): text;
	cmd = (k != 0)? substr(text, k+1): "";
	if (key == "!")
		exec(cmd, 1) | stdout
	else if (key == "dos") {
		dos(cmd " >output");
		f2c("output");
		}
	else if (text != "")
		eval(text) | stdout

	printf ("\n> ") | stdout
	return (0);
	}


/| input input/ {
	interpret(DDEinput);
	}

/| input click/ {
	if (substr(DDEinput, 1, 1) == ">") {
		DDEinput = substr(DDEinput, 3)
		printf ("%s\n", DDEinput) | stdout
		}

	interpret(DDEinput)
	}


BEGIN {
	DDEservice = "ci " PROGwindow
	ctrl(2, DDEservice, 1)

	if (getmod("tty") == 0) {
		inform(DDEservice,
		       "Starten Sie zunchst das Terminal Programm TTY.");
		exit();
		}

	tty = "tty|stdio " PROGwindow
	DDEservice "|input" | tty "!open"

	stdout = tty "!print"
	interpret("\"system ready\"")
	}


END {
#	"" | tty "!close"
	}
