====== subs.pl ====== This is a small assortment of subroutines that I call often in client-side scripts, so I put them together here in one place. To use this file, put it in the same directory as your scripts, and include it like this: require "./subs.pl"; ====== Code ====== # Subroutines for use in client-side crossfire scripts sub wait_for_server { print "watch comc\n"; my $res = ; print "unwatch comc\n"; } # request_line() # Request one line of information from the client # # @param $request # Information to request # # Returns the reply as a scalar # sub request_line1 { my $request = "@_"; # Join any arguments with spaces my @lines; print "request $request\n"; while(){ if( /^request $request (.+)$/ ){ return $1; } } return undef; } sub request_line { my $request = shift; print "request $request\n"; my $reply; while( $reply = ){ # LOG($reply); chomp $reply; last if( $reply =~ s/^request $request // ); } return split ' ', $reply; } sub draw { my $color = shift; my $line = shift; print "draw $color $line\n"; } sub issue { for (@_) { print "issue 1 1 $_\n"; wait_for_server(); } } sub LOG { print STDERR @_, "\n"; } 1;