<?php
require_once($_SERVER['PM_BASE_CONFIG_PATH']);
class maxima_core {
private $executable_command;
protected $dbg_bool;
protected $dbg_info;
public function __construct($dbg=FALSE){
$this->executable_command=constant('PM_MAXIMA_EXEC_CMD');
$this->dbg_bool=$dbg;
$this->dbg_info="";
}
protected function exec($query){// to include package that is loaded by init_command
$descriptor = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/error-log.txt", "a")//constant('PM_SERVER_LOG_DIR')."/maxima/error.log", "a") // stderr is a file to write to
);
$cwd=constant('PM_ACTIVITY_PLUGIN_URL')."/engine_solver";
$MAXIMA_DIR = constant('PM_ACTIVITY_PLUGIN_DIR');
$env=array();
$init_command="display2d:false$" . "PM_ACTIVITY_PLUGIN_URL: \"" . $MAXIMA_DIR . "\"$";
//'load("/home/gabriel/github/moodledata/stack/maximalocal.mac");';
$exec_cmd=$this->executable_command." --quiet";
// --userdir='".constant('PM_ACTIVITY_PLUGIN_DIR')."/engine_solver/maxima_userdir'";
// change
$result=NULL;
$process=proc_open($exec_cmd,$descriptor,$pipes,$cwd,$env);
if(is_resource($process)){
if (!fwrite($pipes[0], $init_command)) {
echo "<br />Could not write to the CAS process!<br />\n";
} else {
fwrite($pipes[0], $query);
fwrite($pipes[0], "quit();");
fclose($pipes[0]);
$result=stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}
}
return $result;
}
public function dbg_info(){
return $this->dbg_info;
}
}
?>