summaryrefslogtreecommitdiff
path: root/src/console/ConsoleController.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-02-05 16:37:36 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-02-05 16:37:36 (GMT)
commit7ae5eaab79a41f31b633ca6f1bfb0dbae2fccb90 (patch)
treeb76fc14cca5e19c5482209f34131973ad1f80e6a /src/console/ConsoleController.cpp
parent8024caec55ff1b93eefe50663d4ddf63934f8d63 (diff)
downloadpowder-7ae5eaab79a41f31b633ca6f1bfb0dbae2fccb90.zip
powder-7ae5eaab79a41f31b633ca6f1bfb0dbae2fccb90.tar.gz
Started intrepreter for tpt script and various things for console
Diffstat (limited to 'src/console/ConsoleController.cpp')
-rw-r--r--src/console/ConsoleController.cpp49
1 files changed, 11 insertions, 38 deletions
diff --git a/src/console/ConsoleController.cpp b/src/console/ConsoleController.cpp
index cf4cdcd..7f1975d 100644
--- a/src/console/ConsoleController.cpp
+++ b/src/console/ConsoleController.cpp
@@ -8,7 +8,7 @@
#include <stack>
#include "ConsoleController.h"
-ConsoleController::ConsoleController(ControllerCallback * callback):
+ConsoleController::ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface):
HasDone(false)
{
consoleModel = new ConsoleModel();
@@ -17,55 +17,28 @@ ConsoleController::ConsoleController(ControllerCallback * callback):
consoleModel->AddObserver(consoleView);
this->callback = callback;
+ this->commandInterface = commandInterface;
}
void ConsoleController::EvaluateCommand(std::string command)
{
+ int returnCode = commandInterface->Command(command);
if(command.length())
- consoleModel->AddLastCommand(ConsoleCommand(command, -1, "Syntax error"));
+ consoleModel->AddLastCommand(ConsoleCommand(command, returnCode, commandInterface->GetLastError()));
else
if(ui::Engine::Ref().GetWindow() == consoleView)
ui::Engine::Ref().CloseWindow();
}
+void ConsoleController::CloseConsole()
+{
+ if(ui::Engine::Ref().GetWindow() == consoleView)
+ ui::Engine::Ref().CloseWindow();
+}
+
std::string ConsoleController::FormatCommand(std::string command)
{
- char * rawText = (char*)command.c_str();
- char * outputData = (char *)calloc(command.length()*6, 1);
- int rawTextLoc = 0;
- int outputDataLoc = 0;
- std::stack<char> pstack;
- while(rawText[rawTextLoc])
- {
- switch(rawText[rawTextLoc])
- {
- case '\\':
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- if(rawText[rawTextLoc])
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- break;
- case '"':
- if(pstack.size() && pstack.top() == '"')
- {
- pstack.pop();
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- outputData[outputDataLoc++] = '\b';
- outputData[outputDataLoc++] = 'w';
- }
- else
- {
- pstack.push('"');
- outputData[outputDataLoc++] = '\b';
- outputData[outputDataLoc++] = 'o';
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- }
- break;
- default:
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- break;
- }
- }
- return outputData;
+ return commandInterface->FormatCommand(command);
}
void ConsoleController::NextCommand()