[LON-CAPA-cvs] cvs: loncom / lonmaxima

raeburn lon-capa-cvs@mail.lon-capa.org
Sat, 03 Feb 2007 04:09:30 -0000


raeburn		Fri Feb  2 23:09:30 2007 EDT

  Modified files:              
    /loncom	lonmaxima 
  Log:
  Tested on FC5 and FC6: 32 bit/64 bit using perl-Expect, perl-IO-Tty, gmp, maxima, maxima-runtime-gcl and sbcl from fedora extras.
  
  ^M (Windows-style) line breaks needed to be removed.
  
  Results of computations were being reported by maxima after $reply to client had already been set (as ''). Caused by duplicate input line ($i\d+) entry: e.g. from maxima transactions:
  (%i2) trigsimp(trigreduce(4*a*x^3-4*a*x^3));
  (%i2) trigsimp(trigreduce(4*a*x^3-4*a*x^3));
  (%o2)                                  0
  
  Now check for output line and make two passes if necessary. (Should this be a while() loop for the case where N passes are needed?).
  
  Substitution of \(%o\d+\) label now functional.
  
  
  
Index: loncom/lonmaxima
diff -u loncom/lonmaxima:1.22 loncom/lonmaxima:1.23
--- loncom/lonmaxima:1.22	Tue Dec 19 12:44:16 2006
+++ loncom/lonmaxima	Fri Feb  2 23:09:30 2007
@@ -3,7 +3,7 @@
 # The LearningOnline Network with CAPA
 # Connect to MAXIMA CAS
 #
-# $Id: lonmaxima,v 1.22 2006/12/19 17:44:16 www Exp $
+# $Id: lonmaxima,v 1.23 2007/02/03 04:09:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -259,7 +259,10 @@
            while (my $cmd=<$client>) {
               &status('Processing command');
               print $command &unescape($cmd);
-              my $reply=&getmaximaoutput($command);
+              my ($reply,$finished,$syntaxerr) = &getmaximaoutput($command);
+              if ((!$finished) && (!$syntaxerr) && ($reply !~ /^Error\:/)) {
+                  ($reply,$finished,$syntaxerr) = &getmaximaoutput($command);
+              }
               print $client &escape($reply)."\n";
               if ($reply=~/^Error\:/) {
                  &logthis('Died through '.$reply);
@@ -305,17 +308,26 @@
     if ($error) {
        return 'Error: '.$error;
     }
+    $output =~ s/\r+//g; # Remove Windows-style linebreaks
+    my $hasoutput=0;
     my $foundoutput=0;
+    my $syntaxerr=0;
     my $realoutput='';
     foreach my $line (split(/\n/,$output)) {
        if ($line=~/\;/) { $foundoutput=1; next; }
        if (!$foundoutput) { next; }
-       my ($label)=($line=~s/^(\(\%o\d+\))//);
+       if ($line=~/^Incorrect syntax:/) { $syntaxerr = 1; next; }
+       (my $label, $line) = ($line=~ /^(\(\%o\d+\))(.+)$/);
        if ($label) {
           $label=~s/\S/ /g;
           $line=$label.$line;
+          $hasoutput = 1;
        }
        $realoutput.=$line."\n";
     }
-    return $realoutput;
+    if (wantarray) {
+        return ($realoutput,$hasoutput,$syntaxerr);
+    } else {
+        return $realoutput;
+    }
 }