Hard Light Productions Forums

Off-Topic Discussion => General Discussion => Topic started by: Sandwich on August 02, 2003, 06:54:08 am

Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 02, 2003, 06:54:08 am
I'm pondering coding up a PHP parser for FS1/2 tables, partially because I'd like to get some experience in parsing text files with PHP, and partially because it might be useful somehow.

Now, first of all, vote whether you think this could end up being useful... the possible applications are quite varied, everything from storing the .tbl info in a real database and outputting parts as needed, to comparing ship stats, to easy adjustment of various ship stats, built-in help for each option, etc etc etc.

Secondly, assuming the majority think this is worthwhile, I'll need some help, primarily in gathering up lists of all possible ship flags, attributes, context help explanations for the options, etc.

Thirdly, again assuming I go ahead with this, is there anyone of you who has past experience with PHP parsing of text files that I can work with? :D
Title: WIP - .TBL PHP Parser?
Post by: an0n on August 02, 2003, 07:06:18 am
Go find DM. He has skillz.
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 02, 2003, 07:44:37 am
DM?
Title: WIP - .TBL PHP Parser?
Post by: an0n on August 02, 2003, 08:07:11 am
http://ironmarch.krabbit.com

Deadman.

He usually lurks on IRC.
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 02, 2003, 02:16:16 pm
I think it would be good for newer modders, but not as useful for veterans.
Title: WIP - .TBL PHP Parser?
Post by: phreak on August 02, 2003, 02:22:02 pm
it would be good to check if any errors exist in table entries before you test it in fs2 and it doesn't work
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 02, 2003, 07:01:10 pm
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 (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php), 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 = "$entry_type: $entry_value";
} else {
$line = "$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;; $entry_value_comment";
}
$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. :nod:
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 02, 2003, 07:05:58 pm
Err.. now, what exactly does this do?
Title: WIP - .TBL PHP Parser?
Post by: mikhael on August 02, 2003, 07:09:29 pm
You know, I suggested something like this about a year ago. I believe Narol castigated me for DAYS about how bad an idea this was because it might make things too easy. ;)


Its still a good idea, in my opinion. Good job, Sandwich.
Title: WIP - .TBL PHP Parser?
Post by: an0n on August 02, 2003, 07:12:20 pm
What's $index?

EDIT: Nevermind, found it.
Title: WIP - .TBL PHP Parser?
Post by: diamondgeezer on August 02, 2003, 07:41:58 pm
Aside from wanting to work with PHP for your own 'enjoyment', what's wrong with Wordpad? Table editing (and FREDding :nervous: ) the way our fathers did it.
Title: WIP - .TBL PHP Parser?
Post by: an0n on August 02, 2003, 07:49:19 pm
The peoples need for progress must be satisifed.

Now either leave or be put to work in the cotton fields.
Title: WIP - .TBL PHP Parser?
Post by: diamondgeezer on August 02, 2003, 11:12:13 pm
Well, it beats mining for coal I suppose
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 12:39:43 am
Quote
Originally posted by an0n
What's $index?

EDIT: Nevermind, found it.


Hehehe - and I plan on further enhancing that llittle variable to be a expanding javascript menu system, allowing one-click access to any ship. :D

Quote
Originally posted by diamondgeezer
Aside from wanting to work with PHP for your own 'enjoyment', what's wrong with Wordpad?


Nothing, except for the same difference that there is between coding HTML in Notepad, and coding it in something that color-codes it. :)

Quote
Originally posted by diamondgeezer
...(and FREDding :nervous: ) the way our fathers did it.


You're insane. ;)
Title: WIP - .TBL PHP Parser?
Post by: J.F.K. on August 03, 2003, 12:59:11 am
I'm still a bit mystified as to what this 'Parser' actually does... mind putting it in plain terms for an idiot like me? :D
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 01:18:18 am
It parses. :p

It'll turn this:

[q]$Name: GTF Ulysses[/q]

Into this:

[q]$Name: GTF Ulysses[/q]

Throughout the whole .tbl file, automagically!
Title: WIP - .TBL PHP Parser?
Post by: J.F.K. on August 03, 2003, 01:34:42 am
... :confused:

Okay, I'm still confused. Do you mean, then, that it changes the formatting (to blue, bold type in this case) of certain strings in the file? But aren't TBL files opened in Wordpad, where such formatting is irrelevant..? :o
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 03, 2003, 03:43:09 am
He means when it's displayed in the parser, it'll be colored like above. The file will still work normally.
Title: WIP - .TBL PHP Parser?
Post by: Exarch on August 03, 2003, 04:03:35 am
Color coding basically helps skim a file faster, so besides all the nifty functions that'll probably be added later, even that is a considerable help :)
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 03, 2003, 03:40:48 pm
What nifty functions?
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 04:28:36 pm
Checkbox selction of ships to include in the output .tbl...

Table display (conventional table - with columns and stuff - as opposed to FS1/2 tables) for ship stats comparison and sorting by attributes...

Table modification via user-friendly (theoretically) interface...

And pretty much anything you can think of - within reason. :p
Title: WIP - .TBL PHP Parser?
Post by: phreak on August 03, 2003, 04:36:08 pm
sandy: it may be easier to use the fs2 source.  i don't know how much C/C++ you know, but its already written and just needs a GUI.  plus you can keep it up to date with all the scp shiz thats going on.  either way, its still a good thing :nod:
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 04:55:00 pm
Quote
Originally posted by PhReAk
sandy: it may be easier to use the fs2 source.  i don't know how much C/C++ you know, but its already written and just needs a GUI.  plus you can keep it up to date with all the scp shiz thats going on.  either way, its still a good thing :nod:


I know zero C/C++, although I do know PHP to an extent. But what does the SCP have to do with this?
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 05:11:32 pm
Ok, PHP help needed. I want to parse through a string, say:

Code: [Select]

$Allowed PBanks:        ( "Subach HL-7" "Morning Star" "Prometheus S"  "Maxim")


And surround every quote pair ( "..." ) with custom HTML code, such as a < SPAN >"..."< /SPAN > tag. I assume I need to use either ereg_replace or preg_replace, but I can't fit my brain around the explanations given in the manual. Anybody have a clue?
Title: WIP - .TBL PHP Parser?
Post by: phreak on August 03, 2003, 05:14:34 pm
Quote
Originally posted by Sandwich
But what does the SCP have to do with this?


we keep adding stuff to the tables (its all optional however)
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 05:18:58 pm
Quote
Originally posted by PhReAk


we keep adding stuff to the tables (its all optional however)


Gotcha, but that shouldn't be a problem. The script will parse through the table, and, for example, keep a list of every primary weapon it runns across (anything between quotes inside parentheses following the "$Allowed PBanks:" statement), not just build a static list from the original files and that's it.

EDIT: So it doesn't get lost on the previous page:

Quote
Originally posted by Sandwich
Ok, PHP help needed. I want to parse through a string, say:

Code: [Select]

$Allowed PBanks:        ( "Subach HL-7" "Morning Star" "Prometheus S"  "Maxim")


And surround every quote pair ( "..." ) with custom HTML code, such as a < SPAN >"..."< /SPAN > tag. I assume I need to use either ereg_replace or preg_replace, but I can't fit my brain around the explanations given in the manual. Anybody have a clue? [/B]
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 03, 2003, 05:49:44 pm
This should work, but no guarantees. You'll probably get an extra space or two at least :nervous:

$Weapons = ' "Subach HL-7" "Morning Star" "Prometheus S"  "Maxim"'; //This is what $Weapons should be to work with this function, ie no parentheses
//$Output is where the final text gets stored

function WeaponParse($Weapons, $Output)
{
     $Weapons = strtr($Weapons,' "','');
     $WeaponsArray = explode('"',$Weapons);

     foreach($WeaponsArray as $Weapon)
     {
          if(strlen(strtr($Weapon," ",'')))
          {
               $Output .= "";
               $Output .= $Weapon;
               $Output .= "
";
          }
     }
}
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 03, 2003, 06:52:28 pm
Thanks, WMCoolmon - but it didn't work. ;) I dunno where it got hung up, but I am unable to troubleshoot scripts that aren't mine - especially ones that use functions I never heard of before. :p But thanks - really! :)

Anyway, I did manage to get my own version working, after discovering the existance of strtok. :D Here's the updates script:


$num_tabs = "\t\t\t"; // number of tab stops between a data line and it's comments; default = 3
$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 = "$entry_type: $entry_value";
} else {
$line = "$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);

// BEGIN find quoted text
$first_quote = strpos($entry_value, '"');
$last_quote = strrpos($entry_value, '"');
if ($first_quote && $last_quote) {
$quoted = substr($entry_value,$first_quote,$last_quote - $first_quote + 1);
$entry_value_new = trim(substr($entry_value,0,$first_quote));
$tok = strtok($quoted,'"');
while ($tok) {
if (trim($tok) == "") {
// do nothing if token is empty
} else {
  $entry_value_new .= " \"$tok\" ";
}
   $tok = strtok('"');
}
$entry_value_new .= trim(substr($entry_value,$last_quote + 1));
$entry_value_old = $entry_value;
$entry_value = $entry_value_new;
}
// END find quoted text

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" . $num_tabs . ";; $entry_value_comment";
}
$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;
?>


And here's (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php) the file again - updated. Lemme know if you spot anything messed up. ;)
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 03, 2003, 07:46:52 pm
Can you make the page background black? It'd be easier on the eyes.
Title: WIP - .TBL PHP Parser?
Post by: Flipside on August 03, 2003, 08:02:11 pm
I've always wondered why tblview wouldn't let you change values, that would have made life so much easier!

Flipside :D
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 04, 2003, 01:07:24 am
Quote
Originally posted by Raa Tor'h
Can you make the page background black? It'd be easier on the eyes.


Done.
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 04, 2003, 02:15:39 am
No problem. It was kind of fun to do some work with PHP again, even if it didn't work. :D

Suggestions/nitpicking:
1) Grouping things like Afterburner and Trail (or maybe even just indenting the optional values) would look better, IMHO.

2) Separating ship specs would give the table a cleaner look.

3) There's still no title. :p
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 04, 2003, 08:31:56 am
Quote
Originally posted by Sandwich


Done.


Thats so much better.

Now that I can see what it is, I can say "not bad, not bad"
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 04, 2003, 08:39:06 am
Quote
Originally posted by WMCoolmon
No problem. It was kind of fun to do some work with PHP again, even if it didn't work. :D

Suggestions/nitpicking:
1) Grouping things like Afterburner and Trail (or maybe even just indenting the optional values) would look better, IMHO.

2) Separating ship specs would give the table a cleaner look.

3) There's still no title. :p


1) You mean the stuff beginning with plus signs? I plan to next.

2) Seperating ship specs? It's all ship specs! :p

3) Meh. :p
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 04, 2003, 02:00:53 pm
Quote
Originally posted by Sandwich

2) Seperating ship specs? It's all ship specs! :p

Separating each individual ship spec, then...so that the GTF Ulysses is separate from the GTF Hercules in some way besides that little space. :p
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 04, 2003, 06:54:40 pm
Gotcha. :)

Added features:
- Indented lines beginning with "+".
- Horizontal rule between unit entries (above every "$Name: ****").
- Linked index of every unit with color-coding according to species, including "Ancient/Ancients" and a special "Other" catch-all, and placed it all in a tidy list. :D

Clickety-click! (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php)


$num_tabs = "\t\t\t"; // number of tab stops between a data line and it's comments; default = 3
$table = file("ships.tbl");
$text = '
';
$html_ul_state = "closed";
$html_li_state = "closed";
while (list (, $line) = each ($table)) {
GLOBAL $html_ul_state;
$line = trim($line);

// BEGIN section check (starts with "#")
if (strpos($line, "#") === 0) { // line begins with '#'?
if ($line == "#End") {
$line = '' . $line . "";
} else {
$tbl_heading1_id++;
if ($html_ul_state == "open") {
$index .= "\n\n";
$html_ul_state = "closed";
}
$index .= '' . $line . '';
$line = '***** CLASS="tbl_heading1_text">' . $line . "";
}
// END check for section

// BEGIN check for comments (start with ";")
} 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 = "$entry_type: $entry_value";
} else {
$line = "$line";
}
// END check for comments

// BEGIN check for subentries (start with "+")
} elseif (strpos($line, "+") === 0) { // line is subentry
if (strchr($line,":")) {
list($entry_type,$entry_value) = explode(":",$line);
$entry_type = trim($entry_type);
$entry_value = trim($entry_value);
$line = "\t$entry_type:\t$entry_value";
} else {
$line = "\t$line";
}
// END check for subentries

// 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);

// BEGIN find quoted text
$first_quote = strpos($entry_value, '"');
$last_quote = strrpos($entry_value, '"');
if ($first_quote && $last_quote) {
$quoted = substr($entry_value,$first_quote,$last_quote - $first_quote + 1);
$entry_value_new = trim(substr($entry_value,0,$first_quote));
$tok = strtok($quoted,'"');
while ($tok) {
if (trim($tok) == "") {
// do nothing if token is empty
} else {
  $entry_value_new .= " \"$tok\" ";
}
   $tok = strtok('"');
}
$entry_value_new .= trim(substr($entry_value,$last_quote + 1));
$entry_value_old = $entry_value;
$entry_value = $entry_value_new;
}
// END find quoted text

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" . $num_tabs . ";; $entry_value_comment";
}
$line = "$entry_type: $entry_value";

// BEGIN check for entry start and name
if ($entry_type == "\$Name") {
if ($html_li_state == "open") {
$index .= "\n\n";
$html_li_state = "closed";
}
if ($html_ul_state == "closed") {
$index .= "\n
    \n";
    $html_ul_state = "open";
    }
    $line = "
    \n
    \n $index .= "\n
  • \n\t";
    $html_li_state = "open";
    $index .= "
    $entry_value";
    $entry_list_id++;
    }
    // END check for entry start and name

    // BEGIN check for species
    if ($entry_type == "\$Species") {
    switch (trim($entry_value)) {
       case "Terran":
       case "Vasudan":
       case "Shivan":
       case "Ancient":
       case "Ancients":
           $index .= "\t($entry_value)
  • ";
           break;
    default:
           $index .= "\t(Other - $entry_value)";
    }
    $html_li_state = "closed";
    }
    // END check for species
    // END data parsing

    } else {
    // blank line
    }

       $text .= $line . "\n";
    }
    $text .= "\n\n
";
echo $index;
echo $text;
?>
Title: WIP - .TBL PHP Parser?
Post by: mikhael on August 04, 2003, 07:55:19 pm
Okay, now for you next trick, lets see you put the index in a frame to the left, like Javadoc does with javacode documentation. (http://java.sun.com/j2se/1.4.2/docs/api/) :D
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 04, 2003, 08:10:45 pm
Yeah, what mik said. That'd make it uberusefulâ„¢ :D
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 04, 2003, 08:15:03 pm
The headings (names) for the fighters don't seem to show up now. :confused:
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 06, 2003, 12:22:13 pm
Quote
Originally posted by WMCoolmon
The headings (names) for the fighters don't seem to show up now. :confused:


I fixed it a while ago, but forgot to post. Sorry.

Quote
Originally posted by mikhael
Okay, now for you next trick, lets see you put the index in a frame to the left, like Javadoc does with javacode documentation. (http://java.sun.com/j2se/1.4.2/docs/api/) :D


Pfft.... small play (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php). ;)

And that's all from one single index.php... it generates the frameset and both the left navigation bar and the main section. :D

Heck, I even added the page title! ;)

Should I keep posting the PHP code? It's getting kinda big... 7kb ATM.
Title: WIP - .TBL PHP Parser?
Post by: kode on August 06, 2003, 02:58:15 pm
Quote
Originally posted by Sandwich



Pfft.... small play (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php). ;)
 


except it doesn't seem to work. at least not for me (using opera)
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 06, 2003, 05:51:44 pm
Quote
Originally posted by kode


except it doesn't seem to work. at least not for me (using opera)


Opera, eh? Try viewing it in IE and see if whatever isn't working works. Did this just get broken with this latest update?

Anyone else using Opera and not being able to view the parser?
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 06, 2003, 06:10:17 pm
Exploder loads it poifect. :)
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 06, 2003, 06:55:22 pm
Oi know, I wanted Kode to load it in Explorer so he could see  how it was supposed to be, and tell me what's different in Opera.
Title: WIP - .TBL PHP Parser?
Post by: kode on August 07, 2003, 04:39:33 am
Quote
Originally posted by Sandwich


Opera, eh? Try viewing it in IE and see if whatever isn't working works. Did this just get broken with this latest update?

Anyone else using Opera and not being able to view the parser?


that navigational thingy didn't work yesterday. seems to work today tho. odd.
Title: WIP - .TBL PHP Parser?
Post by: mikhael on August 07, 2003, 12:54:38 pm
Quote
Originally posted by Sandwich

Pfft.... small play (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php). ;)

And that's all from one single index.php... it generates the frameset and both the left navigation bar and the main section. :D

Heck, I even added the page title! ;)

Should I keep posting the PHP code? It's getting kinda big... 7kb ATM.


You rock my world. Post a link to a txt file containing the code--or add an option to cause the PHP to spit out its own code. Something like "...tbl_parser/index.php?raw", if you follow me.
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 07, 2003, 03:22:02 pm
Quote
Originally posted by Sandwich
I fixed it a while ago, but forgot to post. Sorry.


I still don't see the ship names in the main frame. :confused:
Title: WIP - .TBL PHP Parser?
Post by: Taristin on August 07, 2003, 04:12:06 pm
They're there... I get them atleast.
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 07, 2003, 07:38:19 pm
Quote
Originally posted by WMCoolmon


I still don't see the ship names in the main frame. :confused:


What browser are you using? Take a screenie, if you don't mind. :)
Title: WIP - .TBL PHP Parser?
Post by: Unknown Target on August 07, 2003, 07:44:52 pm
sorry, my head hurts. can someone put this in layman's terms?
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 07, 2003, 08:15:43 pm
Quote
Originally posted by Unknown Target
sorry, my head hurts. can someone put this in layman's terms?


Simple. Go here (http://dynamic4.gamespy.com/~freespace/tbl_parser/index.php) and look at what the page does to a regular ships.tbl. :)

Anyway, after coding in frameset generation, I tried to go over the script, fix a few bugs, and modularize the thing into functions. Ha. Ha-ha. Ha-ha-ha. :rolleyes:

Anyway, after enough frustration for one day, I decided to streamline the whole thing by drawing up a flowchart for the parsing process. Lacking a nearby paper and the strength to get up and hunt one down, I ripped open my cellphone bill envelope and started writing. ;)

I've attached the file - feel free to nitpick and find things I missed before I start coding again. :p
Title: WIP - .TBL PHP Parser?
Post by: Unknown Target on August 07, 2003, 08:56:33 pm
oooooh, ok, major koolio. :yes:

What you're trying to do is make it so that you can edit .TBL formats in this fashion, right? That's a great idea, will really help the new guys with .tbl modding, and streamline the process for the vets ;)
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 07, 2003, 11:52:41 pm
Where have all the ship names gone? (http://members.cox.net/~wmcoolmon/images/shipstbl.gif)

There's a screenshot. :cool:
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 08, 2003, 07:24:14 pm
Quote
Originally posted by Unknown Target
oooooh, ok, major koolio. :yes:

What you're trying to do is make it so that you can edit .TBL formats in this fashion, right? That's a great idea, will really help the new guys with .tbl modding, and streamline the process for the vets ;)


In the end, yeah. First of all, though, is making sure that it parses .TBL files perfectly, otherwise if I try to actually build .TBL files with this thing, it could be majorly screwy.

Quote
Originally posted by WMCoolmon
Where have all the ship names gone? (http://members.cox.net/~wmcoolmon/images/shipstbl.gif)

There's a screenshot. :cool:


Hmm.... that's weird. What color depth are you running at? And which browser?

The white blocks aren't the ship names, BTW - that's the ship species, with each species having a differently colored background - green for Terran, beige for Vasudan, Red for Shivan, and two other colors - teal and blue, I believe - for Ancient(s) and anything else. :)

Mik and anyone else interested, I've attached the source code for the frames version. :)
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on August 09, 2003, 12:11:16 am
Er, ignore that. That's the result of accidentally making a color in the GIF transparent. :nervous: Those look fine, normally.

In the main frame, though, the ship names don't show up - the links don't work, either.

Here's the chunk of missing stuff for the Ulysses:
Code: [Select]
$Name:                          GTF Ulysses
$Short name:            TFight
$Species:                       Terran
+Type:                          XSTR("Space Superiority", 2939)
+Maneuverability:       XSTR("Excellent", 2940)
+Armor:                         XSTR("Light", 2941)
+Manufacturer:          XSTR("Triton / Mekhu", 2942)
+Description: XSTR( " ", 2943)
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on August 09, 2003, 07:37:55 am
Quote
Originally posted by WMCoolmon
Er, ignore that. That's the result of accidentally making a color in the GIF transparent. :nervous: Those look fine, normally.

In the main frame, though, the ship names don't show up - the links don't work, either.

Here's the chunk of missing stuff for the Ulysses:
Code: [Select]
$Name:                          GTF Ulysses
$Short name:            TFight
$Species:                       Terran
+Type:                          XSTR("Space Superiority", 2939)
+Maneuverability:       XSTR("Excellent", 2940)
+Armor:                         XSTR("Light", 2941)
+Manufacturer:          XSTR("Triton / Mekhu", 2942)
+Description: XSTR( " ", 2943)
[/B]


Hmm... that is weird. What version of IE is that happening under? And is that the page online, or are you running the PHP locally or on some other server, perhaps with a differently formatted ships.tbl?
Title: WIP - .TBL PHP Parser?
Post by: mikhael on August 10, 2003, 08:09:55 pm
Quote
Originally posted by WMCoolmon
Er, ignore that. That's the result of accidentally making a color in the GIF transparent. :nervous: Those look fine, normally.

In the main frame, though, the ship names don't show up - the links don't work, either.

Here's the chunk of missing stuff for the Ulysses:
Code: [Select]
$Name:                          GTF Ulysses
$Short name:            TFight
$Species:                       Terran
+Type:                          XSTR("Space Superiority", 2939)
+Maneuverability:       XSTR("Excellent", 2940)
+Armor:                         XSTR("Light", 2941)
+Manufacturer:          XSTR("Triton / Mekhu", 2942)
+Description: XSTR( " ", 2943)
[/B]


Examine the page source in IE when you're missing stuff. You might also want to send Sandwich a copy of the html you're seeing. that would let him see if there's an intermittent failing in the script or other such problem.
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on September 27, 2003, 03:03:51 am
Bumpitty! :)

Ok, I've got a few questions about the .TBL files:

1. What's with these lines? [q]+Description:         XSTR( " ", 2943)
$end_multi_text[/q]

The use of $end_multi_text seems to be optional, and seems to be used after an XSTR() thingy. Can anyone tell me more? SCP dudes, perhaps?

2. The XSTR() itself has those mysterious numbers in the second half. When writing one's own table entry, I've been told to put in a -1 to avoid any conflicts. So what's the purpose of those numbers anyway?

3. Why do some lines start with a "+" as opposed to the regular "$"? Are they sub-data types of some sort?
Title: WIP - .TBL PHP Parser?
Post by: kasperl on September 27, 2003, 03:18:51 am
i can't really help with the tables or PHP stuff, but i like what you're doing, and i see a major use for this in FW (http://nodewar.penguinbomb.com/fleetwars/)
because we were thinking about dynamicly generating everything from the table to the mision itself using PHP.
Title: WIP - .TBL PHP Parser?
Post by: Flaser on September 27, 2003, 09:17:40 am
What really grabed my attention was the possibility to eventually store this in some real database. Now, that would be awsome - SQL anyone?

Beside I think this work should have been done ages ago, Sandwich you're one of my personal heroes!
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on September 27, 2003, 01:30:19 pm
Upgraded to IE 6 and it worked. But I think I found the problem...
$Name: GTF Ulysses
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on September 27, 2003, 07:04:34 pm
Quote
Originally posted by WMCoolmon
Upgraded to IE 6 and it worked. But I think I found the problem...
$Name: GTF Ulysses


Ahh, yes, I found that overlooked tag and fixed it already.

I've got the parser to the point where it parses through the ships.tbl file flawlessly (AFAIK), so now it'sonlt a matter of figuring out how to make it store and retrieve the table data into a database. This could be made sooo complex I don't know where to start.

For example, I can see it eventually being a database that stores every single tbl entry for every ship submitted. In addition, it could store user- and campaign-specific modifications to the baseline entries. So you'd have a GTF Ulysses, a GTF Ulysses (Sandwich interceptor mod), a GTF Ulysses (Styxx's fire-support mod), etc.

You could save and load various selection sets, eg. FS2 standard, Inferno tables, etc, and then add and remove individual ships from that starting point.

Then you'd select "Compile .TBL", and it would piece together a clean .TBL file.
Title: WIP - .TBL PHP Parser?
Post by: kasperl on September 28, 2003, 12:27:51 pm
well, that would sound great.

as for the DB, i'd say store it all under unique names, so starting with the name of the campaign it comes from, or the maker, and then the name of the ship, wityh perhaps an added number. like this:

inf-GTT Argo
sandwich-Ulysses interceptor mod-v1

and then a field in that record containing the name for use in the tbl file itself.
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on September 28, 2003, 07:16:30 pm
;7

Yes!! With a master DB of submitted ship types, it would be possible to make FS2 auto-download the needed TBL info to use a ship.

All you'd need would be a POF with the ship's database ID...
Title: WIP - .TBL PHP Parser?
Post by: kasperl on September 29, 2003, 09:59:16 am
erm, well, i think you should be abeto contain into the DB too, so all you would ned is the exact db name of the ship.
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on September 29, 2003, 11:14:42 am
Sorry to sound harsh, guys, but dream on. :p There isn't a chance that FS2 would download ship info dynamically - the idea is ridiculous, if for no other reason than size and always-on constraints for the poor modem users.
Title: WIP - .TBL PHP Parser?
Post by: WMCoolmon on September 29, 2003, 07:17:43 pm
Quote
Originally posted by Sandwich
Sorry to sound harsh, guys, but dream on. :p There isn't a chance that FS2 would download ship info dynamically - the idea is ridiculous, if for no other reason than size and always-on constraints for the poor modem users.


A single tbl entry isn't that large, really. And if it really is too large...well, there are ways of dealing with that :drevil:
Title: WIP - .TBL PHP Parser?
Post by: Sandwich on September 30, 2003, 01:04:21 am
Yeah, but you were talking about storing the POF as well... might as well store the textures, too... oh, and since the SCP now allows multiple thousands of polies per ship in a mission, the POF size would increase tenfold. :doubt: