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>
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>