# HG changeset patch # User Matti Hamalainen # Date 1294625748 -7200 # Node ID aeb37c6b16fdf5894957593aec8a69666d1028cc # Parent 666d475c8f92bbc820c34a1ec6b15adf8c208e2a Fixes, also added integrated test data. diff -r 666d475c8f92 -r aeb37c6b16fd index.php --- a/index.php Mon Jan 10 03:54:07 2011 +0200 +++ b/index.php Mon Jan 10 04:15:48 2011 +0200 @@ -3,6 +3,16 @@ $pageIndex = "index.php"; require "mcommon.inc.php"; + +// Multi-stack item fixups +$fixItemTable = array( + "(purple|green) gloves" => 'a ${1} glove', + "heavy black metal rings" => "a heavy black metal ring", + "bracelet mades of green crystal" => "a bracelet made of green crystal", + "white cloth packs for holding salves" => "white cloth pack for holding salves", +); + + $fixNumbers = array( "one" => 1, "two" => 2, "three" => 3, "four" => 4, "five" => 5, "six" => 6, "seven" => 7, "eight" => 8, @@ -10,14 +20,6 @@ ); -$fixItemTable = array( - "(purple|green) gloves" => 'a ${1} glove', - "heavy black metal rings" => "a heavy black metal ring", - "bracelet mades of green crystal" => "a bracelet made of green crystal", - "white cloth packs for holding salves" => "white cloth pack for holding salves", -); - - function getJSArraySegment($arr) { $str = ""; @@ -80,8 +82,14 @@

+

" method="post"> + + First, you should provide a list of equipments you wish to manage. Just plain copy & paste of an inventory listing is enough. +You can also test with pre-defined equipments, + by clicking the button. +

Stacks of items are not supported, and few other things may cause problems too. @@ -119,41 +127,39 @@ foreach ($postData as $line) { // Trim whitespace $str = trim($line); + if ($str == "") continue; - if ($str != "") { - // Strip glows and counters from item "handle" - if (preg_match("/^(.+?)\s+(<.+? glow>|\(\d+\/\d+\)|\[\d+\/\d+\])$/", $str, $m)) - $str = $m[1]; + // Strip glows and counters from item "handle" + if (preg_match("/^(.+?)\s+(<.+? glow>|\(\d+\/\d+\)|\[\d+\/\d+\])$/", $str, $m)) + $str = $m[1]; - // Discard multi-item lines - if (preg_match("/^(two|three|four|five|six|seven|eight|nine)\s+(.+?)( labeled as .+|)$/", $str, $m)) { - if (isset($fixNumbers[$m[1]])) { - $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); + // Discard multi-item lines + if (preg_match("/^(many|two|three|four|five|six|seven|eight|nine|ten)\s+(.+?)( labeled as .+|)$/", $str, $m)) { + if (!isset($fixNumbers[$m[1]])) { + $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; } - if ($changed > 0) { - addItems($n, $res.$m[3]); - break; - } + } else { + $res = preg_replace("/".$pat."/", $rep, $m[2], -1, &$changed); + } + if ($changed > 0) { + addItems($n, $res.$m[3]); + break; } - - if ($changed == 0) { - $ignored[$str] = "Unsupported item stack"; - } - } else - $ignored[$str] = "Unparsed stack of many"; - } else - addItems(1, $str); - } + } + if ($changed == 0) { + $ignored[$str] = "Unsupported item stack"; + } + } + } else + addItems(1, $str); } if (count($ignored) > 0) { @@ -165,12 +171,18 @@ foreach ($ignored as $name => $reason) { echo " ".htmlentities($name)."".htmlentities($reason)."\n"; } + +$encData = base64_encode(serialize($data)); ?>

- + +".$encData."\n"; +?> +