Permalink
Browse files

Improved debugging of mimetex

  • Loading branch information...
1 parent 03cd979 commit 1ed0ba1d772f14c5cfbf934c241056814ec48bf8 fiedorow committed Feb 20, 2004
Showing with 42 additions and 17 deletions.
  1. +14 −3 filter/algebra/algebradebug.php
  2. +4 −2 filter/algebra/filter.php
  3. +5 −3 filter/algebra/pix.php
  4. +5 −6 filter/tex/pix.php
  5. +14 −3 filter/tex/texdebug.php
@@ -143,6 +143,9 @@ function tex2image($texexp) {
make_upload_directory($CFG->algebraimagedir);
}
$pathname = "$CFG->dataroot/$CFG->algebraimagedir/$image";
+ if (file_exists($pathname)) {
+ unlink($pathname);
+ }
$windows = 0;
switch (PHP_OS) {
case "Linux":
@@ -159,7 +162,7 @@ function tex2image($texexp) {
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
break;
}
- system($cmd);
+ system($cmd, $status);
}
if ($texexp && file_exists($pathname)) {
$lastmodified = filemtime($pathname);
@@ -173,8 +176,16 @@ function tex2image($texexp) {
readfile("$pathname");
} else {
if (!$windows) {
- $cmd = "$cmd 2>&1";
- echo `$cmd` . "<br>\n";
+ $ecmd = "$cmd 2>&1";
+ echo `$ecmd` . "<br>\n";
+ }
+ echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
+ if ($status == 4) {
+ echo "Status corresponds to illegal instruction<br>\n";
+ } else if ($status == 11) {
+ echo "Status corresponds to bus error<br>\n";
+ } else if ($status == 22) {
+ echo "Status corresponds to abnormal termination<br>\n";
}
echo "Image not found!";
}
@@ -149,7 +149,7 @@ function algebra_filter ($courseid, $text) {
$texexp = `$cmd`;
if (preg_match('/parsehilight/',$texexp)) {
$text = str_replace( $matches[0][$i],"<b>Syntax error:</b> " . $texexp,$text);
- } else {
+ } else if ($texexp) {
$texexp = str_replace('#','\not= ',$texexp);
$texexp = str_replace('%','\leq ',$texexp);
$texexp = str_replace('!','\geq ',$texexp);
@@ -185,7 +185,9 @@ function algebra_filter ($courseid, $text) {
$texcache->timemodified = time();
insert_record("cache_filters",$texcache);
$text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp), $text);
- }
+ } else {
+ $text = str_replace( $matches[0][$i],"<b>Undetermined error:</b> ",$text);
+ }
} else {
$text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texcache->rawtext), $text);
}
View
@@ -49,18 +49,19 @@
$texexp = '\Large ' . $texexp;
switch (PHP_OS) {
case "Linux":
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp) );
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
break;
case "WINNT":
case "WIN32":
case "Windows":
$texexp = str_replace('"','\"',$texexp);
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"");
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
break;
case "Darwin":
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp) );
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
break;
}
+ system($cmd, $status);
}
}
@@ -75,6 +76,7 @@
header("Content-type: $filetype");
readfile("$pathname");
} else {
+ echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
echo "Image not found!";
}
View
@@ -48,21 +48,19 @@
$texexp = '\Large ' . $texexp;
switch (PHP_OS) {
case "Linux":
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp) );
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
break;
case "WINNT":
case "WIN32":
case "Windows":
$texexp = str_replace('"','\"',$texexp);
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"");
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
break;
case "Darwin":
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp) );
- break;
- default:
- system("$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp) );
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
break;
}
+ system($cmd, $status);
}
}
@@ -77,6 +75,7 @@
header("Content-type: $filetype");
readfile("$pathname");
} else {
+ echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
echo "Image not found!";
}
View
@@ -83,6 +83,9 @@ function tex2image($texexp) {
make_upload_directory($CFG->teximagedir);
}
$pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
+ if (file_exists($pathname)) {
+ unlink($pathname);
+ }
$windows = 0;
switch (PHP_OS) {
case "Linux":
@@ -99,7 +102,7 @@ function tex2image($texexp) {
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
break;
}
- system($cmd);
+ system($cmd, $status);
}
if ($texexp && file_exists($pathname)) {
$lastmodified = filemtime($pathname);
@@ -113,8 +116,16 @@ function tex2image($texexp) {
readfile("$pathname");
} else {
if (!$windows) {
- $cmd = "$cmd 2>&1";
- echo `$cmd` . "<br>\n";
+ $ecmd = "$cmd 2>&1";
+ echo `$ecmd` . "<br>\n";
+ }
+ echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
+ if ($status == 4) {
+ echo "Status corresponds to illegal instruction<br>\n";
+ } else if ($status == 11) {
+ echo "Status corresponds to bus error<br>\n";
+ } else if ($status == 22) {
+ echo "Status corresponds to abnormal termination<br>\n";
}
echo "Image not found!";
}

0 comments on commit 1ed0ba1

Please sign in to comment.