diff options
| author | oy <Tom_Adams@web.de> | 2011-01-07 19:33:29 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-01-07 19:33:29 +0100 |
| commit | 26f7c67895dd49e8ed91bf7a4c67aff485119087 (patch) | |
| tree | be08db0707e22f0c4a0077a7b1558c55bceaa0ae /src/engine | |
| parent | 41b8022aa1a941a4b2f3095dd4f8600daf4cd168 (diff) | |
| download | zcatch-26f7c67895dd49e8ed91bf7a4c67aff485119087.tar.gz zcatch-26f7c67895dd49e8ed91bf7a4c67aff485119087.zip | |
fixed console parsing when using the exec command. Closes #381
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/shared/console.cpp | 21 | ||||
| -rw-r--r-- | src/engine/shared/console.h | 32 |
2 files changed, 40 insertions, 13 deletions
diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index 2a290cb3..987e252b 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -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(); } diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index 5cacfd90..30f53cf7 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -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; |