function parseScriptColor($script)
{
$script_exploded = explode("\n",$script);
$result = array();
$scriptkeys = array();
$scriptkeys["operators"] = array();
$scriptkeys["operators"][">"] = ">";
$scriptkeys["operators"]["<"] = "<";
$scriptkeys["operators"]["=="] = "==";
$scriptkeys["operators"]["!="] = "!=";
$scriptkeys["operators"][">="] = ">=";
$scriptkeys["operators"]["<="] = "<=";
$scriptkeys["operators"]["~"] = "~";
$scriptkeys["reserved"] = array();
$scriptkeys["reserved"]["DO"] = "DO";
$scriptkeys["reserved"]["LOOP"] = "LOOP";
$scriptkeys["reserved"]["CALLSUB"] = "CALLSUB";
$scriptkeys["reserved"]["SUB"] = "SUB";
$scriptkeys["reserved"]["RETURNSUB"] = "RETURNSUB";
$scriptkeys["reserved"]["DEFINE"] = "DEFINE";
$scriptkeys["reserved"]["IF"] = "IF";
$scriptkeys["reserved"]["ENDIF"] = "ENDIF";
$scriptkeys["reserved"]["WHILE"] = "WHILE";
$scriptkeys["reserved"]["WEND"] = "WEND";
$scriptkeys["reserved"]["DIVIDE"] = "DIVIDE";
$scriptkeys["reserved"]["ADD"] = "ADD";
$scriptkeys["reserved"]["SUBTRACT"] = "SUBTRACT";
$scriptkeys["reserved"]["MULTIPLY"] = "MULTIPLY";
$scriptkeys["reserved"]["SCRIPT_END"] = "SCRIPT_END";
$scriptkeys["reserved"]["ZERO"] = "ZERO";
$scriptkeys["reserved"]["ONE"] = "ONE";
$scriptkeys["reserved"]["TWO"] = "TWO";
$scriptkeys["reserved"]["VOID"] = "VOID";
$scriptkeys["functions"] = array();
$scriptkeys["functions"]["PRINT_TEXT"] = "PRINT_TEXT";
$scriptkeys["functions"]["SLEEP"] = "SLEEP";
$scriptkeys["functions"]["SET"] = "SET";
$scriptkeys["functions"]["MOVE_TO"] = "MOVE_TO";
$scriptkeys["functions"]["MATH"] = "MATH";
$scriptkeys["functions"]["DISTANCE"] = "DISTANCE";
$scriptkeys["functions"]["COMMAND"] = "COMMAND";
$scriptkeys["functions"]["COUNT_NPC_TARGETME"] = "COUNT_NPC_TARGETME";
$scriptkeys["functions"]["ATTACK_TARGET"] = "ATTACK_TARGET";
$scriptkeys["functions"]["TARGET_NEAREST"] = "TARGET_NEAREST";
$scriptkeys["functions"]["CLICK_NEAREST_ITEM"] = "CLICK_NEAREST_ITEM";
$scriptkeys["datatype"] = array();
$scriptkeys["datatype"]["INT"] = "INT";
$scriptkeys["datatype"]["DOUBLE"] = "DOUBLE";
$scriptkeys["datatype"]["STRING"] = "STRING";
$scriptkeys["datatype"]["NULL"] = "NULL";
$scriptkeys["l2net"] = array();
$scriptkeys["l2net"]["CHAR_CUR_HP"] = "CHAR_CUR_HP";
$scriptkeys["l2net"]["CHAR_MAX_HP"] = "CHAR_MAX_HP";
$scriptkeys["l2net"]["CHAR_X"] = "CHAR_X";
$scriptkeys["l2net"]["CHAR_Y"] = "CHAR_Y";
$scriptkeys["l2net"]["CHAR_Z"] = "CHAR_Z";
$scriptkeys["l2net"]["TARGET_X"] = "TARGET_X";
$scriptkeys["l2net"]["TARGET_Y"] = "TARGET_Y";
$scriptkeys["l2net"]["TARGET_Z"] = "TARGET_Z";
$scriptkeys["l2net"]["TARGET_CUR_HP"] = "TARGET_CUR_HP";
$scriptkeys["l2net"]["NEAREST_ITEM_DISTANCE"] = "NEAREST_ITEM_DISTANCE";
$scriptkeyinfo = array();
$scriptkeyinfo["operators"] = array();
$scriptkeyinfo["functions"] = array();
$scriptkeyinfo["datatype"] = array();
$scriptkeyinfo["l2net"] = array();
$scriptkeyinfo["reserved"] = array();
$scriptkeyinfo["operators"]["color"] = "#0000ff";
$scriptkeyinfo["reserved"]["color"] = "#006600";
$scriptkeyinfo["functions"]["color"] = "#0000FF";
$scriptkeyinfo["datatype"]["color"] = "#660066";
$scriptkeyinfo["l2net"]["color"] = "#c34cc3";
$scriptkeyinfo["operators"]["is_bold"] = true;
$scriptkeyinfo["reserved"]["is_bold"] = true;
$scriptkeyinfo["functions"]["is_bold"] = false;
$scriptkeyinfo["datatype"]["is_bold"] = true;
$scriptkeyinfo["l2net"]["is_bold"] = false;
foreach($script_exploded as $line)
{
$line = $this->parseScriptLine($line, $scriptkeys, $scriptkeyinfo);
$result[] = $line;
}
return $result;
}
function parseScriptLine($line, $scriptkeys, $keyinfo)
{
$tokens_matched = array();
$found_key = false;
$result = "";
$tokens = " \n\r\t";
$patterns[0] = "/\t/";
$patterns[1] = "/^(\n|\r)/";
$patterns[2] = "/(\n|\r)$/";
$replace[0] = " ";
$replace[1] = " ";
$replace[2] = " ";
$line = preg_replace($patterns,$replace,$line);
if (preg_match("/\/\//", $line))
{
$result = "$line";
}
else
{
$token = strtok($line, $tokens);
while( $token !== false )
{
$found_key = false;
foreach($keyinfo as $keyname => $keyarray)
{
if(array_key_exists($token, $scriptkeys[$keyname]))
{
$found_key = true;
$bold = ($keyarray["is_bold"] == true ? "class='bold' ": "");
$result .= "$token ";
break;
}
}
if(!$found_key)
{
$result .= "$token ";
}
$token = strtok($tokens);
}
if(preg_match_all("/".*?"/", $result, $splitLine))
{
foreach($splitLine[0] as $strings)
{
$stringpos = strpos($result, $strings);
$stringlen = strlen($strings);
$replacestring = "$strings";
$result = substr_replace($result, $replacestring, $stringpos, $stringlen);
}
}
}
return $result;
}