fixed inheritance not being used in the base menu style when removing clients from the watch list
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "sm_globals.h"
16 #include "TextParsers.h"
17 #include "HandleSys.h"
19 HandleType_t g_TypeSMC = 0;
21 class ParseInfo : public ITextListener_SMC
35 void ReadSMC_ParseStart()
40 parse_start->PushCell(handle);
41 parse_start->Execute(&result);
45 void ReadSMC_ParseEnd(bool halted, bool failed)
50 parse_end->PushCell(handle);
51 parse_end->PushCell(halted ? 1 : 0);
52 parse_end->PushCell(failed ? 1 : 0);
53 parse_end->Execute(&result);
57 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes)
59 cell_t result = SMCParse_Continue;
63 new_section->PushCell(handle);
64 new_section->PushString(name);
65 new_section->PushCell(opt_quotes ? 1 : 0);
66 new_section->Execute(&result);
69 return (SMCParseResult)result;
72 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
74 cell_t result = SMCParse_Continue;
78 key_value->PushCell(handle);
79 key_value->PushString(key);
80 key_value->PushString(value);
81 key_value->PushCell(key_quotes ? 1 : 0);
82 key_value->PushCell(value_quotes ? 1 : 0);
83 key_value->Execute(&result);
86 return (SMCParseResult)result;
89 SMCParseResult ReadSMC_LeavingSection()
91 cell_t result = SMCParse_Continue;
95 end_section->PushCell(handle);
96 end_section->Execute(&result);
99 return (SMCParseResult)result;
102 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline)
104 cell_t result = SMCParse_Continue;
108 raw_line->PushCell(handle);
109 raw_line->PushString(line);
110 raw_line->PushCell(curline);
111 raw_line->Execute(&result);
114 return (SMCParseResult)result;
117 IPluginFunction *parse_start;
118 IPluginFunction *parse_end;
119 IPluginFunction *new_section;
120 IPluginFunction *key_value;
121 IPluginFunction *end_section;
122 IPluginFunction *raw_line;
126 class TextParseGlobals :
127 public SMGlobalClass,
128 public IHandleTypeDispatch
131 void OnSourceModAllInitialized()
135 /* These cannot be cloned, because they are locked to a specific plugin.
136 * However, we let anyone read them because we don't care.
138 g_HandleSys.InitAccessDefaults(NULL, &sec);
139 sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY;
140 sec.access[HandleAccess_Read] = 0;
142 g_TypeSMC = g_HandleSys.CreateType("SMCParser", this, 0, NULL, &sec, g_pCoreIdent, NULL);
145 void OnSourceModShutdown()
147 g_HandleSys.RemoveType(g_TypeSMC, g_pCoreIdent);
150 void OnHandleDestroy(HandleType_t type, void *object)
152 ParseInfo *parse = (ParseInfo *)object;
157 TextParseGlobals g_TextParseGlobals;
159 static cell_t SMC_CreateParser(IPluginContext *pContext, const cell_t *params)
161 ParseInfo *pInfo = new ParseInfo();
163 Handle_t hndl = g_HandleSys.CreateHandle(g_TypeSMC, pInfo, pContext->GetIdentity(), g_pCoreIdent, NULL);
165 /* Should never happen */
172 pInfo->handle = hndl;
177 static cell_t SMC_SetParseStart(IPluginContext *pContext, const cell_t *params)
179 Handle_t hndl = (Handle_t)params[1];
183 if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
186 return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
189 parse->parse_start = pContext->GetFunctionById((funcid_t)params[2]);
194 static cell_t SMC_SetParseEnd(IPluginContext *pContext, const cell_t *params)
196 Handle_t hndl = (Handle_t)params[1];
200 if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
203 return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
206 parse->parse_end = pContext->GetFunctionById((funcid_t)params[2]);
211 static cell_t SMC_SetReaders(IPluginContext *pContext, const cell_t *params)
213 Handle_t hndl = (Handle_t)params[1];
217 if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
220 return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
223 parse->new_section = pContext->GetFunctionById((funcid_t)params[2]);
224 parse->key_value = pContext->GetFunctionById((funcid_t)params[3]);
225 parse->end_section = pContext->GetFunctionById((funcid_t)params[4]);
230 static cell_t SMC_SetRawLine(IPluginContext *pContext, const cell_t *params)
232 Handle_t hndl = (Handle_t)params[1];
236 if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
239 return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
242 parse->raw_line = pContext->GetFunctionById((funcid_t)params[2]);
247 static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params)
249 Handle_t hndl = (Handle_t)params[1];
253 if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
256 return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
260 pContext->LocalToString(params[2], &file);
262 char path[PLATFORM_MAX_PATH];
263 g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "%s", file);
265 unsigned int line = 0, col = 0;
266 SMCParseError p_err = g_TextParser.ParseFile_SMC(path, parse, &line, &col);
268 cell_t *c_line, *c_col;
269 pContext->LocalToPhysAddr(params[3], &c_line);
270 pContext->LocalToPhysAddr(params[4], &c_col);
275 return (cell_t)p_err;
278 static cell_t SMC_GetErrorString(IPluginContext *pContext, const cell_t *params)
280 const char *str = g_TextParser.GetSMCErrorString((SMCParseError)params[1]);
287 pContext->StringToLocal(params[2], params[3], str);
292 REGISTER_NATIVES(textNatives)
294 {"SMC_CreateParser", SMC_CreateParser},
295 {"SMC_ParseFile", SMC_ParseFile},
296 {"SMC_GetErrorString", SMC_GetErrorString},
297 {"SMC_SetParseStart", SMC_SetParseStart},
298 {"SMC_SetParseEnd", SMC_SetParseEnd},
299 {"SMC_SetReaders", SMC_SetReaders},
300 {"SMC_SetRawLine", SMC_SetRawLine},