PDA

View Full Version : File Parsing


erfg1
03-20-2007, 05:00 PM
Whats wrong with this parser? This is written in C.

char fx[64] = " ";
char loadPath[64], bX[6], bY[6], bZ[6];
gentity_t *fx_runner;
int count2 = 0;

Com_sprintf(loadPath, 1024*4, "mp_effects/%s.dat", mapname.string);
trap_FS_FOpenFile(loadPath, &fil, FS_READ);

if ( fil )
{
trap_FS_Read(line2, 1024, fil);
ef = 0;
fx_runner = G_Spawn();
for(f2 = 0; f2 < 1025; f2++)
{
if(line2[f2] != ' ' && line2[f2] != '\n')
{
if(count2 == 0)
{
//We're getting the effect name
fx[ef] = line2[f2];
ef++;
}
else if(count2 == 1)
{
//We're getting the origin X
bX[ef] = line2[f2];
ef++;
}
else if(count2 == 2)
{
//We're getting the origin Y
bY[ef] = line2[f2];
ef++;
}
else if(count2 == 3)
{
//We're getting the origin Z
bZ[ef] = line2[f2];
ef++;
}
}
else
{
ef = 0;
count2++;
}

//End of line
if(count2 == 4)
{
AddSpawnField("fxFile", fx);
fx_runner->s.origin[2] = atoi(bZ);
fx_runner->s.origin[1] = atoi(bY);
fx_runner->s.origin[0] = atoi(bX);
SP_fx_runner(fx_runner);
count2 = 0;
}
}
G_Printf ("Loaded perminant effects successfully.");
}
trap_FS_FCloseFile( fil );

Here's the file im trying to parse

env/fire 1597 813 -79
env/small_fire_blue 1605 886 -79
env/small_firered 1589 735 -79
env/small_fire_red 1589 735 -79
env/small_fire 1522 816 -79
env/small_fire 1670 809 -79

Here's what im getting back

env/fire at <1597 813 -79>
env/small_fire_blue at <1605 886 -79>
env/small_firered at <1589 735 -79>
env/small_fire_red at <1589 735 -79>
env/small_fire at <1522 816 -79>
<NULL> at <0 809 -79>
<NULL> at <0 0 0>

AhknubisX
03-27-2007, 01:32 AM
Logical error:
Your incrementing 'ef' and it has not been declared any where at all. All types must be declared prior to initialization and usage.

It would appear to me that you are using the 'ef' value as an iterator assignment while you tokenize and parse strings separately in your document. Your doc looks to be a proprietary DB file format and possibly even a 3D designer Plug-in.

You will most certainly need to declare the 'ef' as an integer type in your code's declarations and probably construct a pointer/reference to the 'ef' object. Your 'ef' iterations are being assigned to a type that has not been assigned an address in memory for storage.

As for the actual coding side of this particular problem I must leave you to your own recognicence. I have seen similar problems with undeclared types and references(pointers) and there is help for you. Check out Tutorialized.com and do a web search for pointer types. Another area that might be of interest to you would be Hash types in C as well. I am seeing square brackets and that's making me think of Hashing strings like arrays.

Just a few ideas and leads for you. I wished that I could've been more assistance for you but I'm at my intellectual limit with this situation.

Best regards and happy hunting.