# HG changeset patch # User Matti Hamalainen # Date 1294749373 -7200 # Node ID 35f0c0ce0c51c4eecf35e319d01fd430da912863 # Parent c0dec130ce74c7d5acd0ce32cd2e9f08a74ea4cc Cleanups. diff -r c0dec130ce74 -r 35f0c0ce0c51 index.php --- a/index.php Tue Jan 11 13:45:00 2011 +0200 +++ b/index.php Tue Jan 11 14:36:13 2011 +0200 @@ -46,6 +46,30 @@ } +function performItemFixups($input, $table, &$changed) +{ + $changed = 0; + + foreach ($table as $pat => $rep) { + // Static patterns start with asterisk "*" + if ($pat[0] == "*") { + if (substr($pat, 1) == $input) { + $changed = 1; + return $rep; + } + } else { + // Perform regexp replacment + $res = preg_replace("/".$pat."/", $rep, $input, -1, &$changed); + if ($changed > 0) + return $res; + } + + } + + return $input; +} + + if (isset($_POST["mode"])) { $formMode = intval($_POST["mode"]); } else @@ -136,7 +160,7 @@ if ($str == "") continue; // Strip glows and counters from item "handle" - if (preg_match("/^(.+?)\s+(<.+? glow>|\(\d+\/\d+\)|\[\d+\/\d+\])$/", $str, $m)) + if (preg_match("/^(.+?)\s+(\(glowing\))?\s*(<.+? glow>|\(\d+\/\d+\)|\[\d+\/\d+\])/", $str, $m)) $str = $m[1]; // Discard multi-item lines @@ -145,27 +169,16 @@ $ignored[$str] = "Unparsed stack of many"; } else { $n = $fixNumbers[$m[1]]; - $changed = 0; - foreach ($fixItemTable as $pat => $rep) { - if ($pat[0] == "*") { - if (substr($pat, 1) == $m[2]) { - $res = $rep; - $changed = 1; - } - } else { - $res = preg_replace("/".$pat."/", $rep, $m[2], -1, &$changed); - } - if ($changed > 0) { - addItems($n, $res.$m[3]); - break; - } - } - if ($changed == 0) { + $res = performItemFixups($m[2], $fixStackTable, &$changed); + if ($changed > 0) + addItems($n, $res.$m[3]); + else $ignored[$str] = "Unsupported item stack"; - } } - } else - addItems(1, $str); + } else { + // Other item name fixups + addItems(1, performItemFixups($str, $fixItemTable, &$changed)); + } } if (count($ignored) > 0) { diff -r c0dec130ce74 -r 35f0c0ce0c51 itemfixes.inc.php --- a/itemfixes.inc.php Tue Jan 11 13:45:00 2011 +0200 +++ b/itemfixes.inc.php Tue Jan 11 14:36:13 2011 +0200 @@ -1,7 +1,14 @@ "a book of eternal youth", + "^small crystal box \([a-z ]+\)" => "small crystal box" +); + + // Multi-stack item fixups -$fixItemTable = array( +$fixStackTable = array( "^(purple|green) gloves" => 'a ${1} glove', "^bracelet mades of green crystal" => "bracelet made of green crystal", "^alchemist moulded rings" => "alchemist moulded ring", @@ -11,18 +18,15 @@ // Damiens "^arm protectors called Damien \(\S+\)" => "an arm protector called Damien (${1})", - "^a book of eternal youth ([a-z ]+)" => "a book of eternal youth", // Containers "^white cloth packs for holding salves" => "white cloth pack for holding salves", "^(small|HUGE) shiny boxes for storing minerals" => 'a ${1} shiny box for storing minerals', "^(small|HUGE) sturdy packs for storing potions" => 'a ${1} sturdy pack for storing potions', - "^small crystal box \([a-z ]+\)" => "small crystal box" ); $fixNumbers = array( - "one" => 1, "two" => 2, "three" => 3, "four" => 4,