changeset 52:dd39f6bbc4cb

Add comments.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Mar 2011 22:43:44 +0200
parents 2d65a511ff4e
children eb847818a3be
files index.php results.txt
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Tue Mar 22 22:36:18 2011 +0200
+++ b/index.php	Tue Mar 22 22:43:44 2011 +0200
@@ -293,24 +293,30 @@
 
 alch_matrix_clear();
 
+// Check if we have a non-stale cache of the matrix data
 #if (1)
 if (filemtime($dataFile) > filemtime($cacheFile))
 {
+  $nline = 0;
   $file = fopen($dataFile, "r");
 
   while (($rawline = fgets($file)) !== FALSE) {
+    $nline++;
     $line = trim($rawline);
+    
+    // Skip empty lines and comments
     if ($line == "" || $line[0] == '#') continue;
 
     list ($m, $o, $h, $r) = preg_split("/\s+/", $line, 4);
 
-    // Get indexes
+    // Get indexes for herb, organ and mineral names
     $mn = array_search($m, $dbNames[0]);
     $on = array_search($o, $dbNames[1]);
     $hn = array_search_multi($h, $dbNames[2]);
 
+    // Warn about invalid data
     if ($mn === false || $on === false || $hn === false) {
-      echo "# Invalid data: '$line'<br />\n";
+      echo "Invalid data on line #$nline: '$line'<br />\n";
       continue;
     }
 
@@ -344,23 +350,25 @@
 
   array_walk($mat, "alch_find_pairs");
 
+  // Write cache file
   $cache = @fopen($cacheFile, "w");
   if ($cache !== false) {
     fwrite($cache, serialize($db));
     fclose($cache);
-    echo "Made a new cache.<br />\n";
+    echo "New cache generated.<br />\n";
   } else
     echo "Error writing cache file!<br />\n";
-
 } else {
-
+  // Read and unserialize cached data
   $cache = @file_get_contents($cacheFile);
 
   if ($cache !== false)
     $db = unserialize($cache);
 
   if (isset($db) && $db !== false)
-    echo "Using cache made at " . date ("F d Y H:i:s.", filemtime($cacheFile))."<br>";
+    echo "Using cache made at " . date ("F d Y H:i:s.", filemtime($cacheFile))."<br />\n";
+  else
+    echo "Error reading or unserializing cache, the file may be corrupted or for wrong version.<br />\n";
 }
 
 
--- a/results.txt	Tue Mar 22 22:36:18 2011 +0200
+++ b/results.txt	Tue Mar 22 22:43:44 2011 +0200
@@ -1194,3 +1194,4 @@
 chromium      liver   water_lily    !cure_critical_wounds
 chromium      antenna   arnica    ?indoors_disguise
 chromium      horn   lobelia    -
+chromium      heart   lettuce    ?field_of_fear