mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed console parsing when using the exec command. Closes #381
This commit is contained in:
parent
41b8022aa1
commit
26f7c67895
|
@ -217,7 +217,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr)
|
|||
{
|
||||
while(pStr && *pStr)
|
||||
{
|
||||
CResult *pResult = new(&m_ExecutionQueue.m_pLast->m_Result) CResult;
|
||||
CResult Result;
|
||||
const char *pEnd = pStr;
|
||||
const char *pNextPart = 0;
|
||||
int InString = 0;
|
||||
|
@ -245,24 +245,24 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr)
|
|||
pEnd++;
|
||||
}
|
||||
|
||||
if(ParseStart(pResult, pStr, (pEnd-pStr) + 1) != 0)
|
||||
if(ParseStart(&Result, pStr, (pEnd-pStr) + 1) != 0)
|
||||
return;
|
||||
|
||||
CCommand *pCommand = FindCommand(pResult->m_pCommand, m_FlagMask);
|
||||
CCommand *pCommand = FindCommand(Result.m_pCommand, m_FlagMask);
|
||||
|
||||
if(pCommand)
|
||||
{
|
||||
int IsStrokeCommand = 0;
|
||||
if(pResult->m_pCommand[0] == '+')
|
||||
if(Result.m_pCommand[0] == '+')
|
||||
{
|
||||
// insert the stroke direction token
|
||||
pResult->AddArgument(m_paStrokeStr[Stroke]);
|
||||
Result.AddArgument(m_paStrokeStr[Stroke]);
|
||||
IsStrokeCommand = 1;
|
||||
}
|
||||
|
||||
if(Stroke || IsStrokeCommand)
|
||||
{
|
||||
if(ParseArgs(pResult, pCommand->m_pParams))
|
||||
if(ParseArgs(&Result, pCommand->m_pParams))
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "Invalid arguments... Usage: %s %s", pCommand->m_pName, pCommand->m_pParams);
|
||||
|
@ -270,18 +270,19 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr)
|
|||
}
|
||||
else if(m_StoreCommands && pCommand->m_Flags&CFGFLAG_STORE)
|
||||
{
|
||||
m_ExecutionQueue.AddEntry();
|
||||
m_ExecutionQueue.m_pLast->m_pfnCommandCallback = pCommand->m_pfnCallback;
|
||||
m_ExecutionQueue.m_pLast->m_pCommandUserData = pCommand->m_pUserData;
|
||||
m_ExecutionQueue.AddEntry();
|
||||
m_ExecutionQueue.m_pLast->m_Result = Result;
|
||||
}
|
||||
else
|
||||
pCommand->m_pfnCallback(pResult, pCommand->m_pUserData);
|
||||
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
|
||||
}
|
||||
}
|
||||
else if(Stroke)
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "No such command: %s.", pResult->m_pCommand);
|
||||
str_format(aBuf, sizeof(aBuf), "No such command: %s.", Result.m_pCommand);
|
||||
Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
}
|
||||
|
||||
|
@ -569,7 +570,7 @@ void CConsole::StoreCommands(bool Store)
|
|||
{
|
||||
if(!Store)
|
||||
{
|
||||
for(CExecutionQueue::CQueueEntry *pEntry = m_ExecutionQueue.m_pFirst; pEntry != m_ExecutionQueue.m_pLast; pEntry = pEntry->m_pNext)
|
||||
for(CExecutionQueue::CQueueEntry *pEntry = m_ExecutionQueue.m_pFirst; pEntry; pEntry = pEntry->m_pNext)
|
||||
pEntry->m_pfnCommandCallback(&pEntry->m_Result, pEntry->m_pCommandUserData);
|
||||
m_ExecutionQueue.Reset();
|
||||
}
|
||||
|
|
|
@ -66,6 +66,29 @@ class CConsole : public IConsole
|
|||
|
||||
const char *m_pCommand;
|
||||
const char *m_apArgs[MAX_PARTS];
|
||||
|
||||
CResult() : IResult()
|
||||
{
|
||||
mem_zero(m_aStringStorage, sizeof(m_aStringStorage));
|
||||
m_pArgsStart = 0;
|
||||
m_pCommand = 0;
|
||||
mem_zero(m_apArgs, sizeof(m_apArgs));
|
||||
}
|
||||
|
||||
CResult &operator =(const CResult &Other)
|
||||
{
|
||||
if(this != &Other)
|
||||
{
|
||||
IResult::operator=(Other);
|
||||
int Offset = m_aStringStorage - Other.m_aStringStorage;
|
||||
mem_copy(m_aStringStorage, Other.m_aStringStorage, sizeof(m_aStringStorage));
|
||||
m_pArgsStart = Other.m_pArgsStart + Offset;
|
||||
m_pCommand = Other.m_pCommand + Offset;
|
||||
for(int i = 0; i < Other.m_NumArgs; ++i)
|
||||
m_apArgs[i] = Other.m_apArgs[i] + Offset;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void AddArgument(const char *pArg)
|
||||
{
|
||||
|
@ -97,14 +120,17 @@ class CConsole : public IConsole
|
|||
{
|
||||
CQueueEntry *pEntry = static_cast<CQueueEntry *>(m_Queue.Allocate(sizeof(CQueueEntry)));
|
||||
pEntry->m_pNext = 0;
|
||||
m_pLast->m_pNext = pEntry;
|
||||
if(!m_pFirst)
|
||||
m_pFirst = pEntry;
|
||||
if(m_pLast)
|
||||
m_pLast->m_pNext = pEntry;
|
||||
m_pLast = pEntry;
|
||||
(void)new(&(pEntry->m_Result)) CResult;
|
||||
}
|
||||
void Reset()
|
||||
{
|
||||
m_Queue.Reset();
|
||||
m_pFirst = m_pLast = static_cast<CQueueEntry *>(m_Queue.Allocate(sizeof(CQueueEntry)));
|
||||
m_pLast->m_pNext = 0;
|
||||
m_pFirst = m_pLast = 0;
|
||||
}
|
||||
} m_ExecutionQueue;
|
||||
|
||||
|
|
Loading…
Reference in a new issue