moved demo scripts and docs into the demo directory
[urisagit/Stem.git] / demo / chat2_demo
CommitLineData
4536f655 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
3326d20d 8use File::Basename qw( basename );
9$ENV{PATH} .= ':' . basename( $0 ) . ':.';
c0baaa7d 10<<<<<<< HEAD:bin/chat2_demo
11=======
6b34fa66 12
c0baaa7d 13>>>>>>> origin/master:bin/chat2_demo
3326d20d 14for 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
4536f655 19my @children ;
20
21$SIG{ 'INT' } = \&cleanup ;
22
23if ( $s ) {
24
25 $ssfe = 'ssfe' ;
26 $prompt = '-prompt Stem:' ;
27 $prompt2 = '-prompt Chat:' ;
28 $echo = 'console_echo=1'
29}
30
31foreach $cmd ( split /\n/, <<EOT ) {
32xterm -T Chat1 -n Chat1 -geometry 80x25+XSKIP+0 -e $ssfe $prompt run_stem $echo chat_server
33xterm -T Chat2 -n Chat2 -geometry 80x25+XSKIP+250 -e $ssfe $prompt run_stem $echo chat_client
34xterm -T A -n A -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6666
35xterm -T B -n B -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6667
36xterm -T C -n C -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6668
37xterm -T D -n D -geometry 80xLINE+0+OFF -e $ssfe $prompt2 telnet localhost 6669
38EOT
39
40 $cmd =~ s/XSKIP/$xskip/ ;
41
42 $cmd =~ s/LINE/$line_cnt/ ;
43 $cmd =~ s/OFF/$base_off/ and $base_off += $offset ;
44
45print "$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
3326d20d 551 while wait() != -1;
56
57exit;
4536f655 58
4536f655 59
4536f655 60
61sub cleanup {
62
63 print "clean up\n" ;
64
65 kill 9, @children ;
66 wait ;
67 exit ;
68
69}
70
71sub fork_exec {
72
73 my( @exec ) = @_ ;
74
75 if ( $pid = fork() ) {
76
77 push @children, $pid ;
78 return ;
79 }
80
81 exec @exec ;
82}