#!/usr/local/bin/perl
# Calling Wafe as a subprocess of an "application" program
# Date: May 1 1992
# Author: Gustaf Neumann
$wafeBin = "/usr/bin/X11/wafe";

die "socketpair unsuccessful: $!!\n" unless socketpair(S0,S1,1,1,0);
if ($pid=fork) {
    select(S1); $| = 1;
    select(STDOUT);

    print S1 
          "command hello topLevel label {Hello World}\n"
         ."action hello override {<Btn1Down>: exec(echo Knopf 1)}\n"
         ."action hello override {<Btn2Down>: exec(echo Knopf 2)}\n"
         ."action hello override {<Btn3Down>: exec(echo Knopf 3;echo quit;quit)}\n"
         ."realize\n";

    while (<S1>) {
	chop;
	print "Wafe says: <$_>\n";
	last if /^quit/;
    }
    wait;
} elsif (defined $pid) {
    open(STDOUT, ">&S0");
    open(STDIN, ">&S0");
    close(S0);
    select(STDOUT); $| = 1;
    exec "$wafeBin --d --n";
} else {
    die "fork error: $!\n";
}
