--- loncom/homework/lonmaxima.pm 2007/04/19 17:40:43 1.13 +++ loncom/homework/lonmaxima.pm 2007/08/13 10:21:46 1.20 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Interface routines to MAXIMA CAS # -# $Id: lonmaxima.pm,v 1.13 2007/04/19 17:40:43 raeburn Exp $ +# $Id: lonmaxima.pm,v 1.20 2007/08/13 10:21:46 riegler Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,7 +60,10 @@ sub maximareply { sub blacklisted { my ($cmd)=@_; - foreach my $forbidden ('save','load','plot','lisp','includ','compil','file','batch','stringout','translat','stout','stin','block','system') { + foreach my $forbidden ('save','load','plot','lisp','includ','compil', + 'file','batch','stringout','translat','stout', + 'stin','block','system','concat','read','inchar', + 'outchar','ttyoff','with_stdout','writefile') { if ($cmd=~/$forbidden/s) { return 1; } } return 0; @@ -75,7 +78,9 @@ sub runscript { if ($line=~/\w/) { $reply=&maximareply($socket,$line.";\n"); } if ($reply=~/^Error\:/) { return $reply; } } - $reply=~s/\W//gs; + $reply=~s/^\s*//gs; + $reply=~s/\s*$//gs; + &Apache::lonxml::debug("maxima $fullscript \n reply $reply"); return $reply; } @@ -117,7 +122,7 @@ sub maxima_eval { sub compareterms { my ($socket,$terma,$termb)=@_; - my $difference=$terma.'-'.$termb; + my $difference=$terma.'-('.$termb.')'; if (&blacklisted($difference)) { return 'Error: blacklisted'; } my $reply=&maximareply($socket,'trigsimp(trigreduce('.$difference.'));'); if ($reply=~/^\s*0\s*$/) { return 'true'; } @@ -130,7 +135,10 @@ sub maxima_check { my $socket=&connect(); my $reply=&compareterms($socket,$response,$answer); &disconnect($socket); + # integer to string mappings come from capaParser.h + # 1 maps to 'EXACT_ANS' if ($reply eq 'true') { return 1; } + # 7 maps to 'INCORRECT' return 7; }