Ok, I've got initial parsing completed. The script will put a border around the main sections and a grey BG behind the section title and footer (eg. "#Ship Classes" and "#End"). It will display any comments in grey colored test, and will bold the attribute names (eg.
$Name: GTF Ulysses).
It also displays a list of links to the different sections in the .tbl up top.
Check it out
here, but keep in mind that it's big - upwards of 375Kb (which is the size of the ships.tbl). Note: the comments' color formatting seems to be messed up in Mozilla/Netscape.
Source:
$table = file("ships.tbl");
$text = '
';
while (list (, $line) = each ($table)) {
$line = trim($line);
// BEGIN section check
if (strpos($line, "#") === 0) { // line begins with '#'?
if ($line == "#End") {
$line = '' . $line . "
";
} else {
$tbl_heading1_id++;
$index .= '
' . $line . '';
$line = '***** CLASS="tbl_heading1_text">
' . $line . "";
}
// END check for section
// BEGIN check for comments
} elseif (strpos($line, ";") === 0) { // line is commented
if (strchr($line,":")) {
list($entry_type,$entry_value) = explode(":",$line);
$entry_type = trim($entry_type);
$entry_value = trim($entry_value);
$line = "";
} else {
$line = "";
}
// END check for comments
// BEGIN data parsing
} elseif (!strlen($line) == 0) { // not blank line
list($entry_type,$entry_value) = explode(":",$line);
$entry_type = trim($entry_type);
$entry_value = trim($entry_value);
if (strchr($entry_value,";") === FALSE) {
// no comment found
} else {
list($entry_value_data,$entry_value_comment) = explode(";;",$entry_value);
$entry_value_data = trim($entry_value_data);
$entry_value_comment = trim($entry_value_comment);
$entry_value = "$entry_value_data\t\t\t";
}
$line = "
$entry_type: $entry_value";
//if ($entry_type == "$Name") {
//$entry_list
//}
// END data parsing
} else {
// blank line
}
$text .= $line . "\n";
}
$text .= "\n\n";
echo $index;
echo $text;
?>
Coming next:
- Color coding more sections
- Linking every occurance of any name attribute ($Name: XXXXX) text to that entry (for example, it would link the "Hornet" in every ship's allowable SBanks to the Hornet entry in the weapons.tbl)
- storage of every attribute and value pair in a database.
Comments and code streamline suggestions welcome.
