From: fiedorow Date: Sat, 21 Feb 2004 23:34:09 +0000 (+0000) Subject: Fix for case when $CFG->dirroot contains spaces, especially for Windows X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ddea4cf0704a0eafc0bb4b89d87da5b4b880e022;p=moodle.git Fix for case when $CFG->dirroot contains spaces, especially for Windows --- diff --git a/filter/algebra/algebradebug.php b/filter/algebra/algebradebug.php index 5de7300198..ddbe11f8e2 100644 --- a/filter/algebra/algebradebug.php +++ b/filter/algebra/algebradebug.php @@ -163,6 +163,19 @@ function outputText($texexp) { function tex2image($texexp, $md5) { global $CFG; + $error_message1 = "Your system is not configured to run mimeTeX. "; + $error_message1 .= "You need to download the appropriate
executable "; + $error_message1 .= "from "; + $error_message1 .= "http://moodle.org/download/mimetex/, or obtain the "; + $error_message1 .= "C source
from "; + $error_message1 .= "http://www.forkosh.com/mimetex.zip, compile it and "; + $error_message1 .= "put the executable into your
moodle/filter/tex/ directory. "; + $error_message1 .= "You also need to edit your moodle/filter/algebra/pix.php file
"; + $error_message1 .= ' by adding the line
       case "' . PHP_OS . "\":\n";
+  $error_message1 .= "           \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+  $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+  $error_message1 .= "
You also need to add this to your algebradebug.php file."; + if ($texexp) { $texexp = '\Large ' . $texexp; $lifetime = 86400; @@ -175,22 +188,29 @@ function tex2image($texexp, $md5) { if (file_exists($pathname)) { unlink($pathname); } - $windows = 0; + $commandpath = ""; + $cmd = ""; switch (PHP_OS) { case "Linux": - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp); + $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux"; + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp); break; case "WINNT": case "WIN32": case "Windows": - $windows = 1; - $texexp = str_replace('"','\"',$texexp); - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\""; + $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe"; + $texexp = str_replace('"','\"',$texexp); + $cmd = str_replace(' ','^ ',$commandpath); + $cmd .= " ++ -e \"$pathname\" \"$texexp\""; break; case "Darwin": - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp); + $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin"; + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp); break; } + if (!$cmd) { + error($error_message1); + } system($cmd, $status); } if ($texexp && file_exists($pathname)) { @@ -204,10 +224,8 @@ function tex2image($texexp, $md5) { header("Content-type: $filetype"); readfile("$pathname"); } else { - if (!$windows) { - $ecmd = "$cmd 2>&1"; - echo `$ecmd` . "
\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"; @@ -216,6 +234,15 @@ function tex2image($texexp, $md5) { } else if ($status == 22) { echo "Status corresponds to abnormal termination
\n"; } + if (file_exists($commandpath)) { + echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "
"; + $handle = fopen($commandpath,"rb"); + $contents = fread($handle,16384); + fclose($handle); + echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "
"; + } else { + echo "mimetex executable $commandpath not found!
"; + } echo "Image not found!"; } } @@ -224,17 +251,6 @@ function tex2image($texexp, $md5) { Algebra Filter Debugger -dirroot/filter/algebra/pix.php"; - $PHP_OS = PHP_OS; - $handle = fopen($filename,"r"); - $contents = fread($handle, filesize($filename)); - fclose($handle); - if (!strpos($contents,'case "'. $PHP_OS . '":')) { - echo "WARNING! case \"$PHP_OS\": NOT found in pix.php!!!

"; - } -?>

Please enter an algebraic expression without any surrounding @@ into the text box below. (Click here for help.)

dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp); break; case "WINNT": case "WIN32": case "Windows": $texexp = str_replace('"','\"',$texexp); - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\""; + $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe"; + $cmd = str_replace(' ','^ ',$cmd); + $cmd .= " ++ -e \"$pathname\" \"$texexp\""; break; case "Darwin": - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp); - break; - default: /// To allow drop-in binaries for other platforms - if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { - echo "Make sure you have an appropriate MimeTeX binary here:\n\n"; - echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n"; - echo "and that it has the right permissions set on it as executable program.\n\n"; - echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n"; - echo " http://moodle.org/download/mimetex/"; - exit; - } - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp); + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp); break; + default: /// To allow drop-in binaries for other platforms + if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { + echo "Make sure you have an appropriate MimeTeX binary here:\n\n"; + echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n"; + echo "and that it has the right permissions set on it as executable program.\n\n"; + echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n"; + echo " http://moodle.org/download/mimetex/"; + exit; + } + $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp); + break; } - system($cmd, $status); + system($cmd, $status); } } @@ -88,7 +90,8 @@ readfile("$pathname"); } else { echo "The shell command
$cmd
returned status = $status
\n"; - echo "Image not found!"; + echo "Image not found!
"; + echo "Please try the wwwroot/filter/algebra/algebradebug.php\">debugging script"; } exit; diff --git a/filter/tex/mimetex.exe b/filter/tex/mimetex.exe index 4c5093b6d9..81b15b7725 100755 Binary files a/filter/tex/mimetex.exe and b/filter/tex/mimetex.exe differ diff --git a/filter/tex/pix.php b/filter/tex/pix.php index c910eccf71..46a8ffe830 100644 --- a/filter/tex/pix.php +++ b/filter/tex/pix.php @@ -48,18 +48,20 @@ $texexp = '\Large ' . $texexp; switch (PHP_OS) { case "Linux": - $cmd = "$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); - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\""; + $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe"; + $cmd = str_replace(' ','^ ',$cmd); + $cmd .= " ++ -e \"$pathname\" \"$texexp\""; break; case "Darwin": - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp); + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp); break; - default: /// To allow drop-in binaries for other platforms + default: /// To allow drop-in binaries for other platforms if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { echo "Make sure you have an appropriate MimeTeX binary here:\n\n"; echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n"; @@ -87,7 +89,8 @@ readfile("$pathname"); } else { echo "The shell command
$cmd
returned status = $status
\n"; - echo "Image not found!"; + echo "Image not found!
"; + echo "Please try the wwwroot/filter/tex/texdebug.php\">debugging script"; } exit; diff --git a/filter/tex/texdebug.php b/filter/tex/texdebug.php index 5154f5b996..3242697658 100644 --- a/filter/tex/texdebug.php +++ b/filter/tex/texdebug.php @@ -74,6 +74,19 @@ function outputText($texexp) { function tex2image($texexp) { global $CFG; + $error_message1 = "Your system is not configured to run mimeTeX. "; + $error_message1 .= "You need to download the appropriate
executable "; + $error_message1 .= "from "; + $error_message1 .= "http://moodle.org/download/mimetex/, or obtain the "; + $error_message1 .= "C source
from "; + $error_message1 .= "http://www.forkosh.com/mimetex.zip, compile it and "; + $error_message1 .= "put the executable into your
moodle/filter/tex/ directory. "; + $error_message1 .= "You also need to edit your moodle/filter/tex/pix.php file
"; + $error_message1 .= ' by adding the line
       case "' . PHP_OS . "\":\n";
+  $error_message1 .= "           \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+  $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+  $error_message1 .= "
You also need to add this to your texdebug.php file."; + if ($texexp) { $texexp = '\Large ' . $texexp; $lifetime = 86400; @@ -86,22 +99,29 @@ function tex2image($texexp) { if (file_exists($pathname)) { unlink($pathname); } - $windows = 0; + $commandpath = ""; + $cmd = ""; switch (PHP_OS) { case "Linux": - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp); + $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux"; + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp); break; case "WINNT": case "WIN32": case "Windows": - $windows = 1; - $texexp = str_replace('"','\"',$texexp); - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\""; + $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe"; + $texexp = str_replace('"','\"',$texexp); + $cmd = str_replace(' ','^ ',$commandpath); + $cmd .= " ++ -e \"$pathname\" \"$texexp\""; break; case "Darwin": - $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp); + $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin"; + $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp); break; } + if (!$cmd) { + error($error_message1); + } system($cmd, $status); } if ($texexp && file_exists($pathname)) { @@ -115,10 +135,8 @@ function tex2image($texexp) { header("Content-type: $filetype"); readfile("$pathname"); } else { - if (!$windows) { - $ecmd = "$cmd 2>&1"; - echo `$ecmd` . "
\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"; @@ -127,6 +145,15 @@ function tex2image($texexp) { } else if ($status == 22) { echo "Status corresponds to abnormal termination
\n"; } + if (file_exists($commandpath)) { + echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "
"; + $handle = fopen($commandpath,"rb"); + $contents = fread($handle,16384); + fclose($handle); + echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "
"; + } else { + echo "mimetex executable $commandpath not found!
"; + } echo "Image not found!"; } } @@ -135,24 +162,13 @@ function tex2image($texexp) { TeX Filter Debugger -dirroot/filter/tex/pix.php"; - $PHP_OS = PHP_OS; - $handle = fopen($filename,"r"); - $contents = fread($handle, filesize($filename)); - fclose($handle); - if (!strpos($contents,'case "'. $PHP_OS . '":')) { - echo "WARNING! case \"$PHP_OS\": NOT found in pix.php!!!

"; - } -?>

Please enter an algebraic expression without any surrounding $$ into the text box below. (Click here for help.)

+ value="f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
  1. First click on this button