More consistency of some sort...
Oh god, what has possessed me to do this?
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
17 #include "PluginInfoDatabase.h"
18 #include "PluginSys.h"
20 void PluginSettings::Init()
24 type_val = PluginType_MapUpdated;
31 * :TODO: write the logger, make these errors log instead of being static
32 * NOTE: once we do that, we will have to change some code to ignore sections
35 CPluginInfoDatabase::CPluginInfoDatabase()
43 CPluginInfoDatabase::~CPluginInfoDatabase()
48 void CPluginInfoDatabase::ReadSMC_ParseStart()
50 /* Create or reset our string table */
55 m_strtab = new BaseStringTable(1024);
58 /* Set our internal states to the beginning */
67 SMCParseResult CPluginInfoDatabase::MakeError(const char *fmt, ...)
73 vsnprintf(buffer, sizeof(buffer), fmt, ap);
76 m_errmsg = m_strtab->AddString(buffer);
78 return SMCParse_HaltFail;
81 unsigned int CPluginInfoDatabase::GetSettingsNum()
83 return m_infodb_count;
86 PluginSettings *CPluginInfoDatabase::GetSettingsIfMatch(unsigned int index, const char *filename)
88 BaseMemTable *memtab = m_strtab->GetMemTable();
89 int *table = (int *)memtab->GetAddress(m_infodb);
91 if (!table || index >= m_infodb_count)
96 PluginSettings *plugin = (PluginSettings *)memtab->GetAddress(table[index]);
98 const char *name = m_strtab->GetString(plugin->name);
105 if (!g_PluginSys.TestAliasMatch(name, filename))
113 void CPluginInfoDatabase::GetOptionsForPlugin(PluginSettings *settings, unsigned int opt_num, const char **key, const char **val)
115 PluginOpts *table = (PluginOpts *)m_strtab->GetMemTable()->GetAddress(settings->optarray);
123 if (opt_num >= settings->opts_num)
130 *key = m_strtab->GetString(table[opt_num].key);
131 *val = m_strtab->GetString(table[opt_num].val);
134 SMCParseResult CPluginInfoDatabase::ReadSMC_KeyValue(const char *key,
139 if (cur_plugin != -1)
141 PluginSettings *plugin = (PluginSettings *)m_strtab->GetMemTable()->GetAddress(cur_plugin);
144 if (strcmp(key, "pause") == 0)
146 if (strcasecmp(value, "yes") == 0)
148 plugin->pause_val = true;
150 plugin->pause_val = false;
152 } else if (strcmp(key, "lifetime") == 0) {
153 if (strcasecmp(value, "private") == 0)
155 plugin->type_val = PluginType_Private;
156 } else if (strcasecmp(value, "mapsync") == 0) {
157 plugin->type_val = PluginType_MapUpdated;
158 } else if (strcasecmp(value, "maponly") == 0) {
159 plugin->type_val = PluginType_MapOnly;
160 } else if (strcasecmp(value, "global") == 0) {
161 plugin->type_val = PluginType_Global;
163 return MakeError("Unknown value for key \"lifetime\": \"%s\"", value);
166 return MakeError("Unknown property key: \"%s\"", key);
169 /* Cache every option, valid or not */
170 int keyidx = m_strtab->AddString(key);
171 int validx = m_strtab->AddString(value);
173 BaseMemTable *memtab = m_strtab->GetMemTable();
174 if (plugin->opts_num + 1 > plugin->opts_size)
176 unsigned int oldsize = plugin->opts_size;
179 //right now we don't have many
180 plugin->opts_size = 2;
182 plugin->opts_size *= 2;
184 int newidx = memtab->CreateMem(plugin->opts_size * sizeof(PluginOpts), (void **)&table);
185 /* in case it resized */
186 plugin = (PluginSettings *)memtab->GetAddress(cur_plugin);
187 if (plugin->optarray != -1)
189 void *oldtable = memtab->GetAddress(plugin->optarray);
190 memcpy(table, oldtable, oldsize * sizeof(PluginOpts));
192 plugin->optarray = newidx;
194 table = (PluginOpts *)memtab->GetAddress(plugin->optarray);
196 PluginOpts *opt = &table[plugin->opts_num++];
200 } else if (in_plugins) {
201 return MakeError("Unknown property key: \"%s\"", key);
203 /* Ignore anything we don't know about! */
206 return SMCParse_Continue;
209 SMCParseResult CPluginInfoDatabase::ReadSMC_LeavingSection()
213 if (cur_plugin != -1)
219 /* If the plugin is ending, add it to the table */
220 BaseMemTable *memtab = m_strtab->GetMemTable();
222 if (m_infodb_count + 1 > m_infodb_size)
224 unsigned int oldsize = m_infodb_size;
231 int newidx = memtab->CreateMem(m_infodb_size, (void **)&table);
234 void *oldtable = (int *)memtab->GetAddress(m_infodb);
235 memcpy(table, oldtable, oldsize * sizeof(int));
239 table = (int *)memtab->GetAddress(m_infodb);
241 /* Assign to table and scrap the current plugin */
242 table[m_infodb_count++] = cur_plugin;
250 return SMCParse_Continue;
253 SMCParseResult CPluginInfoDatabase::ReadSMC_NewSection(const char *name, bool opt_quotes)
257 /* If we're not in the main Plugins section, and we don't get it for the name, error out */
258 if (strcmp(name, "Plugins") != 0)
260 return MakeError("Unknown root section: \"%s\"", name);
262 /* Otherwise set our states */
268 if (cur_plugin == -1)
270 /* If we get a plugin node and we don't have a current plugin, create a new one */
271 PluginSettings *plugin;
272 cur_plugin = m_strtab->GetMemTable()->CreateMem(sizeof(PluginSettings), (void **)&plugin);
274 plugin->name = m_strtab->AddString(name);
277 if (!in_options && strcmp(name, "Options") == 0)
281 return MakeError("Unknown plugin sub-section: \"%s\"", name);
286 return SMCParse_Continue;