1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-19 16:47:14 +02:00

Fixed the INI compilation on Linux by reverting to the original library.

Fixed an infinite loop in the parsing of command specification strings.
Added the option to retrieve common configs with a fall back value if they don't exist.
Few other minor changes.
This commit is contained in:
Sandu Liviu Catalin
2016-03-11 20:04:26 +02:00
parent 20ae383c42
commit f27a195b6f
10 changed files with 1032 additions and 100 deletions

View File

@ -1136,8 +1136,10 @@ void CmdListener::ProcSpec(CSStr str)
// Reset current argument specifiers
memset(m_ArgSpec, CMDARG_ANY, sizeof(m_ArgSpec));
// Make sure we have anything to parse
if (!str || *str == 0)
if (!str || *str == '\0')
{
return;
}
// Currently processed argument
Uint32 idx = 0;
// Try to apply the specified type specifiers
@ -1150,7 +1152,9 @@ void CmdListener::ProcSpec(CSStr str)
if (*str == '|')
{
if (idx >= SQMOD_MAX_CMD_ARGS)
{
SqThrowF("Extraneous type specifiers: %d >= %d", idx, SQMOD_MAX_CMD_ARGS);
}
// Move to the next character
++str;
// Advance to the next argument
@ -1160,9 +1164,12 @@ void CmdListener::ProcSpec(CSStr str)
else if (*str != ',')
{
// Ignore non-alphabetic characters
while (*str != 0 && !isalpha(*str)) ++str;
while (*str != 0 && !isalpha(*str))
{
++str;
}
// Apply the type specifier
switch(*str)
switch(*str++)
{
// Did we reached the end of the string?
case '\0':
@ -1178,7 +1185,9 @@ void CmdListener::ProcSpec(CSStr str)
m_ArgSpec[idx] |= CMDARG_INTEGER;
// Disable greedy argument flag if set
if (m_ArgSpec[idx] & CMDARG_GREEDY)
{
m_ArgSpec[idx] ^= CMDARG_GREEDY;
}
} break;
// Is this a float type
case 'f':
@ -1186,7 +1195,9 @@ void CmdListener::ProcSpec(CSStr str)
m_ArgSpec[idx] |= CMDARG_FLOAT;
// Disable greedy argument flag if set
if (m_ArgSpec[idx] & CMDARG_GREEDY)
{
m_ArgSpec[idx] ^= CMDARG_GREEDY;
}
} break;
// Is this a boolean type
case 'b':
@ -1194,7 +1205,9 @@ void CmdListener::ProcSpec(CSStr str)
m_ArgSpec[idx] |= CMDARG_BOOLEAN;
// Disable greedy argument flag if set
if (m_ArgSpec[idx] & CMDARG_GREEDY)
{
m_ArgSpec[idx] ^= CMDARG_GREEDY;
}
} break;
// Is this a string type
case 's':
@ -1202,7 +1215,9 @@ void CmdListener::ProcSpec(CSStr str)
m_ArgSpec[idx] |= CMDARG_STRING;
// Disable greedy argument flag if set
if (m_ArgSpec[idx] & CMDARG_GREEDY)
{
m_ArgSpec[idx] ^= CMDARG_GREEDY;
}
} break;
// Is this a lowercase string?
case 'l':
@ -1211,7 +1226,9 @@ void CmdListener::ProcSpec(CSStr str)
m_ArgSpec[idx] |= CMDARG_LOWER;
// Disable greedy argument flag if set
if (m_ArgSpec[idx] & CMDARG_GREEDY)
{
m_ArgSpec[idx] ^= CMDARG_GREEDY;
}
} break;
// Is this a uppercase string?
case 'u':
@ -1220,7 +1237,9 @@ void CmdListener::ProcSpec(CSStr str)
m_ArgSpec[idx] |= CMDARG_UPPER;
// Disable greedy argument flag if set
if (m_ArgSpec[idx] & CMDARG_GREEDY)
{
m_ArgSpec[idx] ^= CMDARG_GREEDY;
}
} break;
// Unknown type!
default: SqThrowF("Unknown type specifier (%c) at argument: %u", *str, idx);
@ -1351,8 +1370,10 @@ void Register_Command(HSQUIRRELVM vm)
cmdns.Func(_SC("GetOnError"), &Cmd_GetOnError);
cmdns.Func(_SC("SetOnError"), &Cmd_SetOnError);
cmdns.Func(_SC("BindError"), &Cmd_SetOnError);
cmdns.Func(_SC("GetOnAuth"), &Cmd_GetOnAuth);
cmdns.Func(_SC("SetOnAuth"), &Cmd_SetOnAuth);
cmdns.Func(_SC("BindAuth"), &Cmd_SetOnAuth);
cmdns.Func(_SC("GetInvoker"), &Cmd_GetInvoker);
cmdns.Func(_SC("GetInvokerID"), &Cmd_GetInvokerID);
cmdns.Func(_SC("GetName"), &Cmd_GetCommand);

View File

@ -345,13 +345,21 @@ void Core::Terminate()
}
// ------------------------------------------------------------------------------------------------
CSStr Core::GetOption(const String & name) const
CSStr Core::GetOption(CSStr name) const
{
Options::const_iterator elem = m_Options.find(name);
return (elem == m_Options.end()) ? g_EmptyStr : elem->second.c_str();
return (elem == m_Options.end()) ? _SC("") : elem->second.c_str();
}
void Core::SetOption(const String & name, const String & value)
// ------------------------------------------------------------------------------------------------
CSStr Core::GetOption(CSStr name, CSStr value) const
{
Options::const_iterator elem = m_Options.find(name);
return (elem == m_Options.end()) ? value : elem->second.c_str();
}
// ------------------------------------------------------------------------------------------------
void Core::SetOption(CSStr name, CSStr value)
{
m_Options[name] = value;
}

View File

@ -498,8 +498,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Option mutators.
*/
CSStr GetOption(const String & name) const;
void SetOption(const String & name, const String & value);
CSStr GetOption(CSStr name) const;
CSStr GetOption(CSStr name, CSStr value) const;
void SetOption(CSStr name, CSStr value);
/* --------------------------------------------------------------------------------------------
* Retrieve the virtual machine.

View File

@ -50,17 +50,19 @@ static void SetState(Int32 value) { return _Core->SetState(value); }
// ------------------------------------------------------------------------------------------------
static CSStr GetOption(CSStr name) { return _Core->GetOption(name); }
static CSStr GetOptionOr(CSStr name, CSStr value) { return _Core->GetOption(name, value); }
static void SetOption(CSStr name, CSStr value) { return _Core->SetOption(name, value); }
// ================================================================================================
void Register_Core(HSQUIRRELVM vm)
{
RootTable(vm)
.Bind(_SC("Core"), Table(vm)
.Bind(_SC("SqCore"), Table(vm)
.Func(_SC("Bind"), &BindEvent)
.Func(_SC("GetState"), &GetState)
.Func(_SC("SetState"), &SetState)
.Func(_SC("GetOption"), &GetOption)
.Func(_SC("GetOptionOr"), &GetOptionOr)
.Func(_SC("SetOption"), &SetOption)
.Func(_SC("GetBlip"), &GetBlip)
.Func(_SC("GetCheckpoint"), &GetCheckpoint)