Ok, mattn has done something similar for me lately and i'm trying to sum it up (this will be incomplete, but hopefully give an overview)
in your .c or .h file:
#define SHAD(x) (int)&(((shader_t *)0)->x)
value_t valid_shader_values[] =
{
{ "frap", V_STRING, SHAD( sname ) },
{ NULL, 0, 0 }
};
and an entry in src/client/cl_main.c like this:
/*
=================
CL_ParseScriptSecond
=================
*/
void CL_ParseScriptSecond( char *type, char *name, char **text )
{
// check for client interpretable scripts
if ( !strcmp( type, "campaign" ) ) CL_ParseCampaign( name, text );
else if ( !strcmp( type, "stage" ) ) CL_ParseStage( name, text );
else if ( !strcmp( type, "up_entry" ) ) MN_ParseUpEntry( name, text );
//TODO: Parse Base
else if ( !strcmp( type, "base" ) ) MN_ParseBases( name, text );
else if ( !strcmp( type, "tech" ) ) MN_ParseTechnologies( name, text );
else if ( !strcmp( type, "tech" ) ) MN_ParseShaders ( name, text );
}
And finally you need the parser in the .c file (just removed some unneeded stuff):
/*======================
MN_ResetResearch
======================*/
void MN_ParseShaders ( char* id, char** text )
{
value_t *var;
shader_t *shad;
char *errhead = _("MN_ParseShaders: unexptected end of file (names ");
char *tokevn;
// get body
token = COM_Parse( text );
if ( !*text || strcmp( token, "{" ) )
{
Com_Printf( _("MN_ParseShaders: shader def \"%s\" without body ignored\n"), id );
return;
}
if ( numShaders >= MAX_SHADERS )
{
Com_Printf( _("MN_ParseShaders: too many shaders entries\n"), id );
return;
}
// new shader
shad = &theglobalshaderlist[numShaders++]; //TODO
memset( t, 0, sizeof( shader_t ) );
//set standard values
strcpy( shad->sname, id );
do {
// get the name type
token = COM_EParse( text, errhead, id );
if ( !*text ) break;
if ( *token == '}' ) break;
// get values
for ( var = valid_shader_values; var->string; var++ )
if ( !strcmp( token, var->string ) )
{
// found a definition
token = COM_EParse( text, errhead, id );
if ( !*text ) return;
if ( var->ofs && var->type != V_NULL )
Com_ParseValue( shad, token, var->type, var->ofs );
else
// NOTE: do we need a buffer here? for saving or something like that?
Com_Printf(_("MN_ParseShaders Error: - no buffer for shaders - V_NULL not allowed\n"));
break;
}
if ( !var->string )
Com_Printf( _("MN_ParseShaders: unknown token \"%s\" ignored (entry %s)\n"), token, id );
} while ( *text );
}
Note that the "shader" text in the .ufo file will be used globaly, so we need to make sure it hasn't been used elsewhere.
I hope this is not too confusing ... for me it was, but now i think i get at least the basics of parsing.
Werner
PS: the forum will most probably f... up the formatting, so either quote the post and copy&paste it, or ask me - i'll send the original text.