Skip to content
Snippets Groups Projects
Commit a981c04f authored by Chris Sangwin's avatar Chris Sangwin
Browse files

First attempt to remove eval() from locallib.

parent 4209745b
Branches
No related tags found
No related merge requests found
......@@ -51,29 +51,10 @@ function stack_string($key, $a = null) {
}
/**
* Translates a string taken as output from Maxima.
*
* This function takes a variable number of arguments, the first of which is assumed to be the identifier
* of the string to be translated.
* This function takes a feedback string from Maxima and unpacks and translates it.
* @param string $rawfeedback
* @return string
*/
function stack_trans() {
$nargs = func_num_args();
if ($nargs > 0) {
$arglist = func_get_args();
$identifier = func_get_arg(0);
$a = array();
if ($nargs > 1) {
for ($i = 1; $i < $nargs; $i++) {
$index = $i - 1;
$a["m{$index}"] = func_get_arg($i);
}
}
$return = stack_string($identifier, $a);
echo $return;
}
}
function stack_maxima_translate($rawfeedback) {
if (strpos($rawfeedback, 'stack_trans') === false) {
......@@ -82,17 +63,32 @@ function stack_maxima_translate($rawfeedback) {
$rawfeedback = str_replace('[[', '', $rawfeedback);
$rawfeedback = str_replace(']]', '', $rawfeedback);
$rawfeedback = str_replace('\n', '', $rawfeedback);
$rawfeedback = str_replace('\\', '\\\\', $rawfeedback);
$rawfeedback = str_replace('!quot!', '"', $rawfeedback);
// @codingStandardsIgnoreStart
ob_start();
eval($rawfeedback);
$translated = ob_get_contents();
ob_end_clean();
// @codingStandardsIgnoreEnd
$translated = array();
preg_match_all('/stack_trans\(.*?\);/', $rawfeedback, $matches);
$feedback = $matches[0];
foreach ($feedback as $key => $fb) {
$fb = substr($fb, 12, -2);
if (strstr($fb, "' , \"") === false) {
// We only have a feedback tag, with no optional arguments.
$translated[] = trim(stack_string(substr($fb, 1, -1)));
} else {
// We have a feedback tag and some optional arguments.
$tag = substr($fb, 1, strpos($fb, "' , \"") - 1);
$arg = substr($fb, strpos($fb, "' , \"") + 5, -2);
$args = explode('" , "', $arg);
$a = array();
for ($i = 0; $i < count($args); $i++) {
$a["m{$i}"] = $args[$i];
}
$translated[] = trim(stack_string($tag, $a));
}
}
return trim($translated);
return implode(' ', $translated);
}
}
......
......@@ -73,7 +73,7 @@ class stack_cas_configuration {
$this->blocksettings['GNUPLOT_CMD'] = $this->get_plotcommand_win();
} else {
$this->blocksettings['DEL_CMD'] = 'rm';
if (!empty($this->settings->plotcommand)) {
if (!empty(trim($this->settings->plotcommand))) {
$this->blocksettings['GNUPLOT_CMD'] = $this->settings->plotcommand;
} else if (is_readable('/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot')) {
$this->blocksettings['GNUPLOT_CMD'] = '/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment