# HG changeset patch # User Matti Hamalainen # Date 1300826624 -7200 # Node ID dd39f6bbc4cb4166c74ae5cac59299ad9d702be9 # Parent 2d65a511ff4e7dde977ce5881280185db1056cf0 Add comments. diff -r 2d65a511ff4e -r dd39f6bbc4cb index.php --- 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'
\n"; + echo "Invalid data on line #$nline: '$line'
\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.
\n"; + echo "New cache generated.
\n"; } else echo "Error writing cache file!
\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))."
"; + echo "Using cache made at " . date ("F d Y H:i:s.", filemtime($cacheFile))."
\n"; + else + echo "Error reading or unserializing cache, the file may be corrupted or for wrong version.
\n"; } diff -r 2d65a511ff4e -r dd39f6bbc4cb results.txt --- 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