]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for case when $CFG->dirroot contains spaces, especially for Windows
authorfiedorow <fiedorow>
Sat, 21 Feb 2004 23:34:09 +0000 (23:34 +0000)
committerfiedorow <fiedorow>
Sat, 21 Feb 2004 23:34:09 +0000 (23:34 +0000)
filter/algebra/algebradebug.php
filter/algebra/pix.php
filter/tex/mimetex.exe
filter/tex/pix.php
filter/tex/texdebug.php

index 5de73001984826b2737827046fb13b5faefa1bd4..ddbe11f8e204a57c04f8d66004e846e717468173 100644 (file)
@@ -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<br> executable ";
+  $error_message1 .= "from <a href=\"http://moodle.org/download/mimetex/\">";
+  $error_message1 .= "http://moodle.org/download/mimetex/</a>, or obtain the ";
+  $error_message1 .= "C source<br> from <a href=\"http://www.forkosh.com/mimetex.zip\">";
+  $error_message1 .= "http://www.forkosh.com/mimetex.zip</a>, compile it and ";
+  $error_message1 .= "put the executable into your<br> moodle/filter/tex/ directory. ";
+  $error_message1 .= "You also need to edit your moodle/filter/algebra/pix.php file<br>";
+  $error_message1 .= ' by adding the line<br><pre>       case "' . PHP_OS . "\":\n";
+  $error_message1 .= "           \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+  $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+  $error_message1 .= "</pre>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` . "<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";
@@ -216,6 +234,15 @@ function tex2image($texexp, $md5) {
            } else if ($status == 22) {
              echo "Status corresponds to abnormal termination<br>\n";
            }
+           if (file_exists($commandpath)) {
+              echo "File size of mimetex executable  $commandpath is " . filesize($commandpath) . "<br>";
+              $handle = fopen($commandpath,"rb");
+              $contents = fread($handle,16384);
+              fclose($handle);
+              echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br>";
+           } else {
+              echo "mimetex executable $commandpath not found!<br>";
+           }
            echo "Image not found!";
    }
 }
@@ -224,17 +251,6 @@ function tex2image($texexp, $md5) {
 <html>
 <head><title>Algebra Filter Debugger</title></head>
 <body>
-<?PHP
-  require_once("../../config.php");
-  $filename = "$CFG->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 "<b>WARNING!</b> case \"$PHP_OS\": NOT found in pix.php!!!<br><br>";
-  }
-?>
     <p>Please enter an algebraic expression <b>without</b> any surrounding @@ into
        the text box below. (Click <a href="#help">here for help.</a>)
           <form action="algebradebug.php" method="get"
index c74d17692fc4980d8ca4463628def2dac41a4a75..ffb8cb43ca3c842c7c5aa16ecc09f37f7aa259bd 100644 (file)
             $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);
-                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<br>$cmd<br>returned status = $status<br>\n";
-        echo "Image not found!";
+        echo "Image not found!<br>";
+       echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
     }
 
     exit;
index 4c5093b6d98de117df1c8b5606ee90e6326fade4..81b15b77257c8b1df7f585731f5768806623198b 100755 (executable)
Binary files a/filter/tex/mimetex.exe and b/filter/tex/mimetex.exe differ
index c910eccf71423981d5d384d04f67a3cc62847272..46a8ffe8304bc1c79d897b6f9a518c7fa596c443 100644 (file)
             $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<br>$cmd<br>returned status = $status<br>\n";
-        echo "Image not found!";
+        echo "Image not found!<br>";
+        echo "Please try the <a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">debugging script</a>";
     }
 
     exit;
index 5154f5b996c002967e5c8513d587942527922ccd..32426976589bc8c7ce8d130c1e8358f5e3f1bbc7 100644 (file)
@@ -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<br> executable ";
+  $error_message1 .= "from <a href=\"http://moodle.org/download/mimetex/\">";
+  $error_message1 .= "http://moodle.org/download/mimetex/</a>, or obtain the ";
+  $error_message1 .= "C source<br> from <a href=\"http://www.forkosh.com/mimetex.zip\">";
+  $error_message1 .= "http://www.forkosh.com/mimetex.zip</a>, compile it and ";
+  $error_message1 .= "put the executable into your<br> moodle/filter/tex/ directory. ";
+  $error_message1 .= "You also need to edit your moodle/filter/tex/pix.php file<br>";
+  $error_message1 .= ' by adding the line<br><pre>       case "' . PHP_OS . "\":\n";
+  $error_message1 .= "           \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+  $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+  $error_message1 .= "</pre>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` . "<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";
@@ -127,6 +145,15 @@ function tex2image($texexp) {
            } else if ($status == 22) {
             echo "Status corresponds to abnormal termination<br>\n";
            }
+           if (file_exists($commandpath)) {
+              echo "File size of mimetex executable  $commandpath is " . filesize($commandpath) . "<br>";
+              $handle = fopen($commandpath,"rb");
+              $contents = fread($handle,16384);
+              fclose($handle);
+              echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br>";
+           } else {
+              echo "mimetex executable $commandpath not found!<br>";
+           }
            echo "Image not found!";
    }
 }
@@ -135,24 +162,13 @@ function tex2image($texexp) {
 <html>
 <head><title>TeX Filter Debugger</title></head>
 <body>
-<?PHP
-  require_once("../../config.php");
-  $filename = "$CFG->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 "<b>WARNING!</b> case \"$PHP_OS\": NOT found in pix.php!!!<br><br>";
-  }
-?>
   <p>Please enter an algebraic expression <b>without</b> any surrounding $$ into
        the text box below. (Click <a href="#help">here for help.</a>)
           <form action="texdebug.php" method="get"
            target="inlineframe">
             <center>
              <input type="text" name="tex" size=50
-                    value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
+                    value="f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
             </center>
            <ol>
            <li>First click on this button <input type="submit" name="ShowDB" value="Show DB Entry">