added check for connected when triggered method is called. can't trigger
[urisagit/Stem.git] / bin / chat2_demo
1 #!/usr/local/bin/perl -s
2
3 $line_cnt = 10 ;
4 $offset = 175 ;
5 $base_off = 0 ;
6 $xskip = ( $^O eq 'solaris' ) ? 600 : 500 ;
7
8 use File::Basename qw( basename );
9 $ENV{PATH} .= ':' . basename( $0 ) . ':.';
10 for my $prog qw( run_stem xterm telnet ) {
11     die "Can't find $prog in PATH\n" if
12         system( "which $prog >/dev/null 2>&1" ) != 0;
13 }
14
15 my @children ;
16
17 $SIG{ 'INT' } = \&cleanup ;
18
19 if ( $s ) {
20
21         $ssfe = 'ssfe' ;
22         $prompt = '-prompt Stem:' ;
23         $prompt2 = '-prompt Chat:' ;
24         $echo = 'console_echo=1'
25 }
26
27 foreach $cmd ( split /\n/, <<EOT ) {
28 xterm -T Chat1 -n Chat1 -geometry 80x25+XSKIP+0   -e $ssfe $prompt run_stem $echo  chat_server
29 xterm -T Chat2 -n Chat2 -geometry 80x25+XSKIP+250 -e $ssfe $prompt run_stem $echo  chat_client
30 xterm -T A -n A -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6666
31 xterm -T B -n B -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6667
32 xterm -T C -n C -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6668
33 xterm -T D -n D -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6669
34 EOT
35
36         $cmd =~ s/XSKIP/$xskip/ ;
37
38         $cmd =~ s/LINE/$line_cnt/ ;
39         $cmd =~ s/OFF/$base_off/ and $base_off += $offset ;
40
41 print "$cmd\n" ;
42
43         @cmd = split ' ', $cmd ;
44
45         s/:/: / for @cmd ;
46
47         fork_exec( @cmd ) ;
48         sleep 2 unless $cmd =~ /localhost/ ;
49 }
50
51 1 while wait() != -1;
52
53 exit;
54
55
56
57 sub cleanup {
58
59         print "clean up\n" ;
60
61         kill 9, @children ;
62         wait ;  
63         exit ;
64
65 }
66
67 sub fork_exec {
68
69         my( @exec ) = @_ ;
70
71         if ( $pid = fork() ) {
72
73                 push @children, $pid ;
74                 return ;
75         }
76
77         exec @exec ;
78 }