in reply to expect.pm problem
$mapfile="toy2.map"; $outfile="toy2.smv"; open(spcmap,"<",$mapfile) || die("Couldn't read $mapfile: $!"); expectsmv(); close($mapfile); sub expectsmv { my $exp = new Expect; my ($bout, $aout, $err); $exp->log_stdout(0); $exp->raw_pty(1); $exp->manual_stty(1); my $command="NuSMV -int"; $exp->spawn($command) or die "Cannot spawn $command: $!\n"; #$exp->log_file("expect_log"); # Remove the banner # $exp->send("\n"); my $patidx = $exp->expect(undef,'NuSMV > ', '-re','NuSMV\s+>\s+' ); #$exp->clear_accum(); #Setup NuSMV and load model file $exp->send("read_model -i $outfile \n"); $exp->send("process_model \n"); #$err = $exp->error; #if($err != 0){ print "Error=", $err ;} #$exp->clear_accum(); while(1) { print "B2S > "; my $cmd = <STDIN>; if($cmd =~ /\s*quit\s+/){ last; $exp->soft_close(); } elsif($cmd =~ /\s*query\s+./) { my($q, $c) = split(" ",$cmd,2); #$cmd = nusmv_q_trans($c); chomp($cmd); $exp->clear_accum(); if($cmd !~ /\b*error1\b*/){ $cmd = "check_spec -p \" $cmd \" "; print "\n $cmd \n"; $exp->send($cmd);} else { print "\n Error \n"; } #Do some pattern matching with either the simple interface my $patidx = $exp->expect(undef,'NuSMV > ', '-re','NuSMV\s+>\s+' ); $err = $exp->exp_error(); if($err != 0){ print "Error=", $err ;} else{ # print $patidx; ($bout = $exp->exp_before) =~ tr/\r//d; $err = $bout; #$bout = nusmv_res_trans($bout); print $bout; } } # end of elsif else # Not a Query { $exp->send($cmd); my $patidx = $exp->expect(undef,'NuSMV > ', '-re','NuSMV\s+>\s+' ); $err = $exp->exp_error; if($exp->error() != 0){ print $exp->error(); last;} else{ ($bout = $exp->exp_before) =~ tr/\r//d; ($aout = $exp->exp_after) =~ tr/\r//d; print $bout; } } #end of else } $exp->clear_accum(); } #end of subroutine #Routine for Translating Query into nusmv format sub nusmv_q_trans { my ($cmd) = @_; #change species names to bngl S# format # search for a species name; beginning with alphabet and replace with +S# found from hash print $cmd; #$cmd =~ s/\b([a-zA-Z])\w*\b/S$smap{$1} /g; $cmd =~ s{ \b([a-zA-Z])\w*\b } { $smap{$1} ? "S$smap{$1}" : return "error1" }xge; $cmd =~ tr/_//d; return $cmd; } sub nusmv_res_trans { my ($res) = @_; $res =~ s/\bS(\d+)\b/$spar[$1]/g; return $res; }
20050713 ysth: reparented this original question under follow that had more info
|
|---|