Merge commit 'origin/master' into HEAD
[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 <<<<<<< HEAD:bin/chat2_demo
11 =======
12
13 >>>>>>> origin/master:bin/chat2_demo
14 for my $prog qw( run_stem xterm telnet ) {
15     die "Can't find $prog in PATH\n" if
16         system( "which $prog >/dev/null 2>&1" ) != 0;
17 }
18
19 my @children ;
20
21 $SIG{ 'INT' } = \&cleanup ;
22
23 if ( $s ) {
24
25         $ssfe = 'ssfe' ;
26         $prompt = '-prompt Stem:' ;
27         $prompt2 = '-prompt Chat:' ;
28         $echo = 'console_echo=1'
29 }
30
31 foreach $cmd ( split /\n/, <<EOT ) {
32 xterm -T Chat1 -n Chat1 -geometry 80x25+XSKIP+0   -e $ssfe $prompt run_stem $echo  chat_server
33 xterm -T Chat2 -n Chat2 -geometry 80x25+XSKIP+250 -e $ssfe $prompt run_stem $echo  chat_client
34 xterm -T A -n A -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6666
35 xterm -T B -n B -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6667
36 xterm -T C -n C -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6668
37 xterm -T D -n D -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6669
38 EOT
39
40         $cmd =~ s/XSKIP/$xskip/ ;
41
42         $cmd =~ s/LINE/$line_cnt/ ;
43         $cmd =~ s/OFF/$base_off/ and $base_off += $offset ;
44
45 print "$cmd\n" ;
46
47         @cmd = split ' ', $cmd ;
48
49         s/:/: / for @cmd ;
50
51         fork_exec( @cmd ) ;
52         sleep 2 unless $cmd =~ /localhost/ ;
53 }
54
55 1 while wait() != -1;
56
57 exit;
58
59
60
61 sub cleanup {
62
63         print "clean up\n" ;
64
65         kill 9, @children ;
66         wait ;  
67         exit ;
68
69 }
70
71 sub fork_exec {
72
73         my( @exec ) = @_ ;
74
75         if ( $pid = fork() ) {
76
77                 push @children, $pid ;
78                 return ;
79         }
80
81         exec @exec ;
82 }