From: fiedorow Date: Fri, 20 Feb 2004 01:44:31 +0000 (+0000) Subject: Improved debugging of mimetex X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1ed0ba1d772f14c5cfbf934c241056814ec48bf8;p=moodle.git Improved debugging of mimetex --- diff --git a/filter/algebra/algebradebug.php b/filter/algebra/algebradebug.php index 0201dfaf3a..27fcaf7d50 100644 --- a/filter/algebra/algebradebug.php +++ b/filter/algebra/algebradebug.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` . "
\n"; + $ecmd = "$cmd 2>&1"; + echo `$ecmd` . "
\n"; + } + echo "The shell command
$cmd
returned status = $status
\n"; + if ($status == 4) { + echo "Status corresponds to illegal instruction
\n"; + } else if ($status == 11) { + echo "Status corresponds to bus error
\n"; + } else if ($status == 22) { + echo "Status corresponds to abnormal termination
\n"; } echo "Image not found!"; } diff --git a/filter/algebra/filter.php b/filter/algebra/filter.php index 05ace6f7ca..510151c2ed 100644 --- a/filter/algebra/filter.php +++ b/filter/algebra/filter.php @@ -149,7 +149,7 @@ function algebra_filter ($courseid, $text) { $texexp = `$cmd`; if (preg_match('/parsehilight/',$texexp)) { $text = str_replace( $matches[0][$i],"Syntax error: " . $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],"Undetermined error: ",$text); + } } else { $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texcache->rawtext), $text); } diff --git a/filter/algebra/pix.php b/filter/algebra/pix.php index b75fc21f0d..30c8e5969b 100644 --- a/filter/algebra/pix.php +++ b/filter/algebra/pix.php @@ -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
$cmd
returned status = $status
\n"; echo "Image not found!"; } diff --git a/filter/tex/pix.php b/filter/tex/pix.php index be1abc2f81..2a1b0accf4 100644 --- a/filter/tex/pix.php +++ b/filter/tex/pix.php @@ -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
$cmd
returned status = $status
\n"; echo "Image not found!"; } diff --git a/filter/tex/texdebug.php b/filter/tex/texdebug.php index 67c489723a..710e271e02 100644 --- a/filter/tex/texdebug.php +++ b/filter/tex/texdebug.php @@ -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` . "
\n"; + $ecmd = "$cmd 2>&1"; + echo `$ecmd` . "
\n"; + } + echo "The shell command
$cmd
returned status = $status
\n"; + if ($status == 4) { + echo "Status corresponds to illegal instruction
\n"; + } else if ($status == 11) { + echo "Status corresponds to bus error
\n"; + } else if ($status == 22) { + echo "Status corresponds to abnormal termination
\n"; } echo "Image not found!"; }