2007-02-03 19:37:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Log$
|
|
|
|
// Revision 1.3 2007/02/03 19:37:19 jbravo
|
|
|
|
// Adding CVS headers to new files in CVS.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
#include "g_parser.h"
|
|
|
|
|
|
|
|
#define BUFFER_SIZE (32 * 1024)
|
|
|
|
static char scriptBuffer[BUFFER_SIZE];
|
|
|
|
|
|
|
|
// Parser states //////////////////////////////////////////////
|
|
|
|
|
|
|
|
TParseState STATE_Base;
|
|
|
|
TParseState STATE_Main;
|
|
|
|
TParseState STATE_Restrictions;
|
|
|
|
TParseState STATE_Rotation;
|
2005-09-19 21:39:31 +00:00
|
|
|
TParseState STATE_Rotation_Map;
|
|
|
|
TParseState STATE_Team;
|
|
|
|
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// BASE STATE /////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Functions //////////////////////////////////////////////////
|
2005-09-19 21:39:31 +00:00
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
SCRIPT_FUNC(Base_To_Main)
|
|
|
|
{
|
|
|
|
SCRIPT_PUSH_STATE(STATE_Main);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
2005-09-19 21:39:31 +00:00
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
SCRIPT_FUNC(Base_To_Restrictions)
|
|
|
|
{
|
|
|
|
SCRIPT_PUSH_STATE(STATE_Restrictions);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
2005-09-19 21:39:31 +00:00
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
SCRIPT_FUNC(Base_To_Rotation)
|
|
|
|
{
|
|
|
|
SCRIPT_PUSH_STATE(STATE_Rotation);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
2005-09-19 21:39:31 +00:00
|
|
|
|
|
|
|
SCRIPT_FUNC(Base_To_Team)
|
|
|
|
{
|
|
|
|
SCRIPT_PUSH_STATE(STATE_Rotation);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
// State definition ///////////////////////////////////////////
|
2005-09-19 21:39:31 +00:00
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
SCRIPT_STATE(STATE_Base, NO_DATA)
|
|
|
|
{
|
|
|
|
ADD_RULE("[main]", Base_To_Main)
|
|
|
|
ADD_RULE("[restrictions]", Base_To_Restrictions)
|
|
|
|
ADD_RULE("[rotation]", Base_To_Rotation)
|
|
|
|
ADD_RULE("/*", SFN_SkipComment)
|
|
|
|
ADD_RULE("//", SFN_SkipLineComment)
|
|
|
|
END_STATE_MARKER
|
|
|
|
};
|
2005-09-19 21:39:31 +00:00
|
|
|
// END BASE STATE /////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// MAIN STATE /////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Functions //////////////////////////////////////////////////
|
|
|
|
|
2009-07-04 03:37:46 +00:00
|
|
|
SCRIPT_FUNC_TOKENS(Main_Cvar)
|
2005-09-18 21:11:22 +00:00
|
|
|
{
|
2005-09-19 21:39:31 +00:00
|
|
|
NEEDS_TOKENS(2, tokens);
|
2005-09-18 21:11:22 +00:00
|
|
|
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
|
|
|
// State definition ///////////////////////////////////////////
|
|
|
|
|
|
|
|
SCRIPT_STATE(STATE_Main, NO_DATA)
|
|
|
|
{
|
|
|
|
ADD_RULE("[/main]", SFN_PopState)
|
|
|
|
ADD_RULE("cvar", Main_Cvar)
|
|
|
|
ADD_RULE("/*", SFN_SkipComment)
|
|
|
|
ADD_RULE("//", SFN_SkipLineComment)
|
|
|
|
END_STATE_MARKER
|
|
|
|
};
|
2005-09-19 21:39:31 +00:00
|
|
|
// END MAIN STATE /////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// TEAM STATE /////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Functions //////////////////////////////////////////////////
|
|
|
|
|
2009-07-04 03:37:46 +00:00
|
|
|
SCRIPT_FUNC_TOKENS(Team_Name)
|
2005-09-19 21:39:31 +00:00
|
|
|
{
|
|
|
|
NEEDS_TOKENS(1, token);
|
|
|
|
G_Printf("Team name: %s\n", token[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
2009-07-04 03:37:46 +00:00
|
|
|
SCRIPT_FUNC_TOKENS(Team_Outfit)
|
2005-09-19 21:39:31 +00:00
|
|
|
{
|
|
|
|
NEEDS_TOKENS(1, token);
|
|
|
|
G_Printf("Team skin: %s\n", token[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
|
|
|
// State definition ///////////////////////////////////////////
|
|
|
|
|
|
|
|
SCRIPT_STATE(STATE_Team, NO_DATA)
|
|
|
|
{
|
|
|
|
ADD_RULE("[/team]", SFN_PopState)
|
|
|
|
ADD_RULE("name", Team_Name)
|
|
|
|
ADD_RULE("outfit", Team_Outfit)
|
|
|
|
ADD_RULE("/*", SFN_SkipComment)
|
|
|
|
ADD_RULE("//", SFN_SkipLineComment)
|
|
|
|
END_STATE_MARKER
|
|
|
|
};
|
|
|
|
// END TEAM STATE /////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// ROTATION STATE /////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Functions //////////////////////////////////////////////////
|
|
|
|
|
2005-09-19 21:39:31 +00:00
|
|
|
SCRIPT_FUNC(Rotation_To_Map)
|
|
|
|
{
|
|
|
|
SCRIPT_PUSH_STATE(STATE_Rotation_Map);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
// State definition ///////////////////////////////////////////
|
|
|
|
|
|
|
|
SCRIPT_STATE(STATE_Rotation, NO_DATA)
|
|
|
|
{
|
|
|
|
ADD_RULE("[/rotation]", SFN_PopState)
|
2005-09-19 21:39:31 +00:00
|
|
|
ADD_RULE("[map]", Rotation_To_Map)
|
|
|
|
ADD_RULE("/*", SFN_SkipComment)
|
|
|
|
ADD_RULE("//", SFN_SkipLineComment)
|
|
|
|
END_STATE_MARKER
|
|
|
|
};
|
|
|
|
// END ROTATION STATE /////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// MAP STATE //////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Functions //////////////////////////////////////////////////
|
|
|
|
|
2009-07-04 03:37:46 +00:00
|
|
|
SCRIPT_FUNC_TOKENS(Map_Name)
|
2005-09-19 21:39:31 +00:00
|
|
|
{
|
|
|
|
NEEDS_TOKENS(1, token);
|
|
|
|
G_Printf("Map: %s\n", token[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
2009-07-04 03:37:46 +00:00
|
|
|
SCRIPT_FUNC_TOKENS(Map_Cvar)
|
2005-09-19 21:39:31 +00:00
|
|
|
{
|
|
|
|
NEEDS_TOKENS(2, tokens);
|
|
|
|
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
|
|
|
// State definition ///////////////////////////////////////////
|
|
|
|
|
|
|
|
SCRIPT_STATE(STATE_Rotation_Map, NO_DATA)
|
|
|
|
{
|
|
|
|
ADD_RULE("[/map]", SFN_PopState)
|
|
|
|
ADD_RULE("map", Map_Name)
|
|
|
|
ADD_RULE("cvar", Map_Cvar)
|
2005-09-18 21:11:22 +00:00
|
|
|
ADD_RULE("/*", SFN_SkipComment)
|
|
|
|
ADD_RULE("//", SFN_SkipLineComment)
|
|
|
|
END_STATE_MARKER
|
|
|
|
};
|
2005-09-19 21:39:31 +00:00
|
|
|
// END MAP STATE //////////////////////////////////////////////
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// RESTRICTIONS STATE /////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
// Functions //////////////////////////////////////////////////
|
|
|
|
|
2009-07-04 03:37:46 +00:00
|
|
|
SCRIPT_FUNC_TOKENS(Restrictions_Cvar)
|
2005-09-18 21:11:22 +00:00
|
|
|
{
|
2005-09-19 21:39:31 +00:00
|
|
|
NEEDS_TOKENS(2, tokens);
|
2005-09-18 21:11:22 +00:00
|
|
|
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
END_SCRIPT_FUNC()
|
|
|
|
|
2005-09-19 21:39:31 +00:00
|
|
|
// State definition ///////////////////////////////////////////
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
SCRIPT_STATE(STATE_Restrictions, NO_DATA)
|
|
|
|
{
|
|
|
|
ADD_RULE("[/restrictions]", SFN_PopState)
|
|
|
|
ADD_RULE("cvar", Restrictions_Cvar)
|
|
|
|
ADD_RULE("/*", SFN_SkipComment)
|
|
|
|
ADD_RULE("//", SFN_SkipLineComment)
|
|
|
|
END_STATE_MARKER
|
|
|
|
};
|
2005-09-19 21:39:31 +00:00
|
|
|
// END RESTRICTIONS STATE /////////////////////////////////////
|
|
|
|
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void G_ParseScript(const char *fname)
|
|
|
|
{
|
|
|
|
fileHandle_t file;
|
|
|
|
int len = trap_FS_FOpenFile(fname, &file, FS_READ);
|
|
|
|
|
|
|
|
if (!file)
|
2005-09-19 21:39:31 +00:00
|
|
|
{
|
|
|
|
G_Printf(S_COLOR_RED " Cannot open file '%s'.\n", fname);
|
2005-09-18 21:11:22 +00:00
|
|
|
return;
|
2005-09-19 21:39:31 +00:00
|
|
|
}
|
2005-09-18 21:11:22 +00:00
|
|
|
|
|
|
|
trap_FS_Read(scriptBuffer, len, file);
|
|
|
|
scriptBuffer[len] = 0;
|
|
|
|
|
|
|
|
trap_FS_FCloseFile(file);
|
|
|
|
|
|
|
|
Script_ParseString(scriptBuffer, &STATE_Base);
|
2005-09-19 21:39:31 +00:00
|
|
|
}
|
|
|
|
|