--- loncom/homework/lonmaxima.pm	2006/12/11 17:37:43	1.6
+++ loncom/homework/lonmaxima.pm	2006/12/15 22:11:43	1.9
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines to MAXIMA CAS
 #
-# $Id: lonmaxima.pm,v 1.6 2006/12/11 17:37:43 www Exp $
+# $Id: lonmaxima.pm,v 1.9 2006/12/15 22:11:43 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,6 +31,7 @@ package Apache::lonmaxima;
 use strict;
 use IO::Socket;
 use Apache::lonnet;
+use Apache::response();
 use LONCAPA;
 
 sub connect {
@@ -68,18 +69,37 @@ sub blacklisted {
 sub runscript {
     my ($socket,$fullscript)=@_;
     if (&blacklisted($fullscript)) { return 'Error: blacklisted'; }
-    return &maximareply($socket,$fullscript);
+    my $reply;
+    $fullscript=~s/[\n\r\l]//gs;
+    foreach my $line (split(/\;/s,$fullscript)) {
+	if ($line=~/\w/) { $reply=&maximareply($socket,$line.";\n"); }
+	if ($reply=~/^Error\:/) { return $reply; }
+    }
+    $reply=~s/\W//gs;
+    return $reply;
+}
+
+sub maxima_cas_formula_fix {
+   my ($expression)=@_;
+   return &Apache::response::implicit_multiplication($expression);
 }
 
 sub maxima_run {
-    my ($script,$submission,$arguments) = @_;
+    my ($script,$submission,$argument) = @_;
     my $socket=&connect();
-    my $fullscript=$script;
+    my $fullscript='';
+    my $submission_index=1;
+    foreach my $submission_component (split(/\s*\,\s*/,$submission)) {
+	$fullscript.="RESPONSE[$submission_index]:".&maxima_cas_formula_fix($submission_component).";\n";
+	$submission_index++;
+    }
+    my $argument_index=1;
+    foreach my $argument_component (@{$argument}) {
+	$fullscript.="LONCAPALIST[$argument_index]:$argument_component;\n";
+	$argument_index++;
+    }
+    $fullscript.=$script;
     my $reply=&runscript($socket,$fullscript);
-#    &Apache::lonnet::logthis('Script:'.$fullscript);
-#    &Apache::lonnet::logthis('Sub:'.$submission);
-#    &Apache::lonnet::logthis('Arg:'.$arguments);
-
     &disconnect($socket);
     if ($reply=~/^\s*true\s*$/) { return 'EXACT_ANS'; }
     if ($reply=~/^\s*false\s*/) { return 'INCORRECT'; }