no message

This commit is contained in:
Andrei Drexler 2005-09-19 21:39:31 +00:00
parent ff3f8c5ccf
commit d1b890dddc
3 changed files with 125 additions and 17 deletions

View file

@ -93,7 +93,7 @@ TParseFunc Script_FindHandler(char *token, TParseState* state)
}
__inline void Script_InitStateStack(TStateStack *stack)
ID_INLINE void Script_InitStateStack(TStateStack *stack)
{
stack->top = 0;
}
@ -119,7 +119,7 @@ void Script_ParseString(char *str, TParseState *baseState)
handler(&str, &stateStack);
} else {
SCRIPT_INFO(SHOW_WARNING)
G_Printf("* Warning: unknown token, '%s'.\n", token);
G_Printf(S_COLOR_YELLOW "* Warning: unknown token, '%s'.\n", token);
END_SCRIPT_INFO();
}
}
@ -145,7 +145,7 @@ SCRIPT_FUNC(SFN_SkipComment)
return 1;
}
SCRIPT_INFO(SHOW_ERROR)
G_Printf("* ERROR: end of input found in comment.\n");
G_Printf(S_COLOR_RED "* ERROR: end of input found in comment.\n");
END_SCRIPT_INFO();
return 0;
}
@ -165,7 +165,7 @@ SCRIPT_FUNC(SFN_SkipLineComment)
}
}
SCRIPT_INFO(SHOW_ERROR)
G_Printf("* ERROR: end of input found in comment.\n");
G_Printf(S_COLOR_RED "* ERROR: end of input found in comment.\n");
END_SCRIPT_INFO();
return 0;
}

View file

@ -62,7 +62,7 @@ typedef enum
extern int SCRIPT_SHOW_LEVEL;
#define SCRIPT_INFO(level) if (SCRIPT_SHOW_LEVEL <= (level)) {
#define END_SCRIPT_INFO() }
#define END_SCRIPT_INFO() }
#define NEEDS_TOKENS(num, name)\
char *name[num];\
@ -99,7 +99,7 @@ extern int SCRIPT_SHOW_LEVEL;
///////////////////////////////////////////////////////////////
__inline int Script_PushState(TStateStack *stack, TParseState *state)
ID_INLINE int Script_PushState(TStateStack *stack, TParseState *state)
{
if (stack->top >= STATE_STACK_SIZE)
{
@ -113,7 +113,7 @@ __inline int Script_PushState(TStateStack *stack, TParseState *state)
return 1;
}
__inline int Script_GetTopState(const TStateStack *stack, TParseState **state)
ID_INLINE int Script_GetTopState(const TStateStack *stack, TParseState **state)
{
if (!state)
return 1;
@ -130,7 +130,7 @@ __inline int Script_GetTopState(const TStateStack *stack, TParseState **state)
return 1;
}
__inline int Script_PopState(TStateStack *stack, TParseState **state)
ID_INLINE int Script_PopState(TStateStack *stack, TParseState **state)
{
stack->top--;
if (stack->top < 0)

View file

@ -9,35 +9,46 @@ TParseState STATE_Base;
TParseState STATE_Main;
TParseState STATE_Restrictions;
TParseState STATE_Rotation;
TParseState STATE_Rotation_Map;
TParseState STATE_Team;
///////////////////////////////////////////////////////////////
// BASE STATE /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Functions //////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
SCRIPT_FUNC(Base_To_Main)
{
SCRIPT_PUSH_STATE(STATE_Main);
return 0;
}
END_SCRIPT_FUNC()
///////////////////////////////////////////////////////////////
SCRIPT_FUNC(Base_To_Restrictions)
{
SCRIPT_PUSH_STATE(STATE_Restrictions);
return 0;
}
END_SCRIPT_FUNC()
///////////////////////////////////////////////////////////////
SCRIPT_FUNC(Base_To_Rotation)
{
SCRIPT_PUSH_STATE(STATE_Rotation);
return 0;
}
END_SCRIPT_FUNC()
///////////////////////////////////////////////////////////////
SCRIPT_FUNC(Base_To_Team)
{
SCRIPT_PUSH_STATE(STATE_Rotation);
return 0;
}
END_SCRIPT_FUNC()
// State definition ///////////////////////////////////////////
///////////////////////////////////////////////////////////////
SCRIPT_STATE(STATE_Base, NO_DATA)
{
ADD_RULE("[main]", Base_To_Main)
@ -47,6 +58,9 @@ SCRIPT_STATE(STATE_Base, NO_DATA)
ADD_RULE("//", SFN_SkipLineComment)
END_STATE_MARKER
};
// END BASE STATE /////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// MAIN STATE /////////////////////////////////////////////////
@ -55,7 +69,7 @@ SCRIPT_STATE(STATE_Base, NO_DATA)
SCRIPT_FUNC(Main_Cvar)
{
NEEDS_TOKENS(1, tokens);
NEEDS_TOKENS(2, tokens);
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
return 0;
}
@ -71,21 +85,109 @@ SCRIPT_STATE(STATE_Main, NO_DATA)
ADD_RULE("//", SFN_SkipLineComment)
END_STATE_MARKER
};
// END MAIN STATE /////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// TEAM STATE /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Functions //////////////////////////////////////////////////
SCRIPT_FUNC(Team_Name)
{
NEEDS_TOKENS(1, token);
G_Printf("Team name: %s\n", token[0]);
return 0;
}
END_SCRIPT_FUNC()
SCRIPT_FUNC(Team_Outfit)
{
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 /////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// ROTATION STATE /////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Functions //////////////////////////////////////////////////
SCRIPT_FUNC(Rotation_To_Map)
{
SCRIPT_PUSH_STATE(STATE_Rotation_Map);
return 0;
}
END_SCRIPT_FUNC()
// State definition ///////////////////////////////////////////
SCRIPT_STATE(STATE_Rotation, NO_DATA)
{
ADD_RULE("[/rotation]", SFN_PopState)
ADD_RULE("[map]", Rotation_To_Map)
ADD_RULE("/*", SFN_SkipComment)
ADD_RULE("//", SFN_SkipLineComment)
END_STATE_MARKER
};
// END ROTATION STATE /////////////////////////////////////////
///////////////////////////////////////////////////////////////
// MAP STATE //////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Functions //////////////////////////////////////////////////
SCRIPT_FUNC(Map_Name)
{
NEEDS_TOKENS(1, token);
G_Printf("Map: %s\n", token[0]);
return 0;
}
END_SCRIPT_FUNC()
SCRIPT_FUNC(Map_Cvar)
{
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)
ADD_RULE("/*", SFN_SkipComment)
ADD_RULE("//", SFN_SkipLineComment)
END_STATE_MARKER
};
// END MAP STATE //////////////////////////////////////////////
///////////////////////////////////////////////////////////////
@ -95,12 +197,13 @@ SCRIPT_STATE(STATE_Rotation, NO_DATA)
SCRIPT_FUNC(Restrictions_Cvar)
{
NEEDS_TOKENS(1, tokens);
NEEDS_TOKENS(2, tokens);
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
return 0;
}
END_SCRIPT_FUNC()
// State definition ///////////////////////////////////////////
SCRIPT_STATE(STATE_Restrictions, NO_DATA)
{
@ -110,8 +213,9 @@ SCRIPT_STATE(STATE_Restrictions, NO_DATA)
ADD_RULE("//", SFN_SkipLineComment)
END_STATE_MARKER
};
// END RESTRICTIONS STATE /////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
void G_ParseScript(const char *fname)
@ -120,7 +224,10 @@ void G_ParseScript(const char *fname)
int len = trap_FS_FOpenFile(fname, &file, FS_READ);
if (!file)
{
G_Printf(S_COLOR_RED " Cannot open file '%s'.\n", fname);
return;
}
trap_FS_Read(scriptBuffer, len, file);
scriptBuffer[len] = 0;
@ -128,4 +235,5 @@ void G_ParseScript(const char *fname)
trap_FS_FCloseFile(file);
Script_ParseString(scriptBuffer, &STATE_Base);
}
}