Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ file parser: suggestions needed

Started by Alessandro Jul 31, 2011 at 9:14 AM 2 replies 1.1k views
Original Post
Alessandro
Alessandro
Hi, I need to parse a text file and retrieve the items marked in [color="#FF8C00"]orange. I'd like to hear suggestions of what kind of algorithm or parsing tecnique I could use. Thanks for any help...

The file looks like this:


[color="#FF8C00"]prop waterpottop
{
storageOffset 0 0 0
objFileGeom 0 0 [color="#FF8C00"]:Runtime:Geometries:AM:AfricanVillage:craft:water pot cap.obj
}
[color="#FF8C00"]prop waterpot
{
storageOffset 0 0 0
objFileGeom 0 0 [color="#FF8C00"]:Runtime:Geometries:AM:AfricanVillage:craft:water pot.obj
}

prop waterpottop [color="#2E8B57"]// these are the properties related to the above "prop waterpottop"
{
propagatingScale Scale
{
name scale
[color="#FF8C00"]initValue 1
}

material [color="#FF8C00"]Water_Pot_Top
{
KdColor 0.980392 0.976471 0.996078 1
KaColor 0 0 0 0
KsColor 0.384314 0.384314 0.384314 0.2
textureMap "[color="#FF8C00"]:Runtime:textures:AM:AfricanVillage:craft:water-pot-top.jpg" 0 0
}
}


prop waterpot [color="#2E8B57"]// these are the properties related to the above "prop waterpot"
{
propagatingScale Scale
{
name scale
[color="#FF8C00"]initValue 1
}

material [color="#FF8C00"]Water_Pot
{
KdColor 0.980392 0.976471 0.996078 1
KaColor 0 0 0 0
KsColor 0.384314 0.384314 0.384314 0.2
textureMap "[color="#FF8C00"]:Runtime:textures:AM:AfricanVillage:craft:water-pot.jpg" 0 0
}
}
ApochPiQ
ApochPiQ
Your data looks to be very well-formatted in the sense that it isn't really necessary to be all that "smart" when parsing it. In other words, you can just use std::ifstream to read it out of the file, one chunk at a time. No need for anything more sophisticated than that.
dutt
dutt
if line[0,4] == "prop" return rest of line / add to token list or whatever you want to do.
elif line[0,something] == "material" return rest of line
etc etc, you get the idea, shouldn't be too hard.
If you do want to do something "smart" anyway I'd use a regexp to retrieve them, although I've never used regexps in C++ only python/php/c# but I figure it can't be that much harder.
[size="1"]trassel (thread lib)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.