Annotation of loncom/homework/lonmaxima.pm, revision 1.2

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Interface routines to MAXIMA CAS
                      3: #
1.2     ! www         4: # $Id: lonmaxima.pm,v 1.1 2006/03/11 16:28:03 www Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28:  
                     29: package Apache::lonmaxima;
                     30:  
                     31: use strict;
                     32: use IO::Socket;
                     33: use Apache::lonnet;
                     34: 
                     35: sub connect {
                     36:    return IO::Socket::UNIX->new(Peer    => $Apache::lonnet::perlvar{'lonSockDir'}.'/maximasock',
                     37: 				Type    => SOCK_STREAM,
                     38: 				Timeout => 10);
                     39: }
                     40: 
                     41: sub disconnect {
                     42:     my ($socket)=@_;
                     43:     if ($socket) { close($socket); }
                     44: }
                     45: 
                     46: sub maximareply {
                     47:     my ($socket,$cmd)=@_;
                     48:     if ($socket) {
                     49: 	print $socket &Apache::lonnet::escape($cmd)."\n";
                     50:         my $reply=<$socket>;
                     51:         chomp($reply);
                     52:         if ($reply=~/^Incorrect/) { $reply='Error: '.$reply; }
                     53:         return &Apache::lonnet::unescape($reply);
                     54:     } else {
                     55:         return 'Error: no connection.';
                     56:     }
                     57: }
                     58: 
                     59: sub blacklisted {
                     60:     my ($cmd)=@_;
                     61:     foreach my $forbidden ('save','load','plot','lisp','includ','compil','file','batch','stringout','translat','stout','stin','block','system') {
1.2     ! www        62: 	if ($cmd=~/$forbidden/s) { return 1; }
1.1       www        63:     } 
                     64:     return 0;
                     65: }
                     66: 
                     67: sub compareterms {
                     68:     my ($socket,$terma,$termb)=@_;
                     69:     my $difference=$terma.'-'.$termb;
                     70:     if (&blacklisted($difference)) { return 'Error: blacklisted'; }
                     71:     my $reply=&maximareply($socket,'trigsimp(trigreduce('.$difference.'));');
                     72:     if ($reply=~/^\s*0\s*$/) { return 'true'; }
                     73:     if ($reply=~/^Error\:/) { return $reply; }
                     74:     return 'false';
                     75: }
                     76:  
                     77: 1;
                     78: __END__;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>