#!/afs/athena/contrib/perl/perl

require 'chat2.pl';

($server, $port) = ('madlab.sprl.umich.edu', 3000);

sub get_weather {
    local($station) = @_;
    
    $closeme = &chat'open_port($server, $port);
    &listen(2);
    &chat'print($station."\n");
    while($forecast!~/CITY FORECAST MENU/){
	$forecast .= &listen(1);
	&chat'print("\n");
    }
    &chat'print("x\n");
    &chat'close($closeme);
    return $forecast;
}

sub listen {
        local($secs) = @_;
        local($return,$tmp) = "";
        while (length($tmp = &chat'expect($secs, '(.|\n)+', '$&'))) {
                print $tmp if $trace;
                $return .= $tmp;
        }
        $return;
}

sub get_states {
    local($station) = @_;
    
    $closeme = &chat'open_port($server, $port);
    &chat'expect(3, 'forecast city code:', '1');    &chat'print("\n");
    &chat'expect(1, 'Selection:', '1');             &chat'print("1\n");
    &chat'expect(1, 'Selection:', '1');             &chat'print("4\n");

# parse the list of states
    &chat'expect(1, '\n +-+ *\n', '1');
    @list = split(/\s\s+/, &chat'expect(2, '\n[^\n]+for menu:', '$` . "\n"'));

    while (@list) {
      $code = shift(@list);
      $state = shift(@list);


sub get_something_else {
    print "in Boston...\n";
    while (&chat'expect(5, '\n[^\n]+to exit:', '$main\'fore .= $`; 1',
                     '\n[^\n]+for menu:', '$main\'fore .= $` . "\n"; 0')) {
       print "...continuing...\n";
       &chat'print("\n");
    }
    print "done\n";
    &chat'print("x\n");
    &chat'close($closeme);
    return $fore;
}

print do get_wexp ('BOS');


