aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorPaul Gilbert2017-09-24 12:18:15 -0400
committerGitHub2017-09-24 12:18:15 -0400
commit47f6c2e9b9687150da6d5d1498fce90523706c28 (patch)
tree2b9c3b5424ce427098cfd770ef09784d482b2b24 /gui
parent3333432b4dc35b65d27423ab7860fae068b13d5e (diff)
parent1ecb27e6cc32eba24079e9b28aea414319c6cbcf (diff)
downloadscummvm-rg350-47f6c2e9b9687150da6d5d1498fce90523706c28.tar.gz
scummvm-rg350-47f6c2e9b9687150da6d5d1498fce90523706c28.tar.bz2
scummvm-rg350-47f6c2e9b9687150da6d5d1498fce90523706c28.zip
Merge pull request #1010 from dreammaster/debugger_params
GUI: Support double quoted debugger parameters
Diffstat (limited to 'gui')
-rw-r--r--gui/console.cpp4
-rw-r--r--gui/debugger.cpp63
-rw-r--r--gui/debugger.h6
3 files changed, 61 insertions, 12 deletions
diff --git a/gui/console.cpp b/gui/console.cpp
index 27b38ac78b..f99197c32d 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -480,9 +480,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
}
void ConsoleDialog::defaultKeyDownHandler(Common::KeyState &state) {
- if (state.ascii == '~' || state.ascii == '#') {
- slideUpAndClose();
- } else if (state.hasFlags(Common::KBD_CTRL)) {
+ if (state.hasFlags(Common::KBD_CTRL)) {
specialKeys(state.keycode);
} else if ((state.ascii >= 32 && state.ascii <= 127) || (state.ascii >= 160 && state.ascii <= 255)) {
for (int i = _promptEndPos - 1; i >= _currentPos; i--)
diff --git a/gui/debugger.cpp b/gui/debugger.cpp
index a570d86b70..1de322ae93 100644
--- a/gui/debugger.cpp
+++ b/gui/debugger.cpp
@@ -289,17 +289,11 @@ bool Debugger::handleCommand(int argc, const char **argv, bool &result) {
bool Debugger::parseCommand(const char *inputOrig) {
int num_params = 0;
const char *param[256];
- char *input = strdup(inputOrig); // One of the rare occasions using strdup is OK (although avoiding strtok might be more elegant here).
// Parse out any params
- char *tok = strtok(input, " ");
- if (tok) {
- do {
- param[num_params++] = tok;
- } while ((tok = strtok(NULL, " ")) != NULL);
- } else {
- param[num_params++] = input;
- }
+ // One of the rare occasions using strdup is OK, since splitCommands needs to modify it
+ char *input = strdup(inputOrig);
+ splitCommand(input, num_params, &param[0]);
// Handle commands first
bool result;
@@ -399,6 +393,57 @@ bool Debugger::parseCommand(const char *inputOrig) {
return true;
}
+void Debugger::splitCommand(char *input, int &argc, const char **argv) {
+ byte c;
+ enum states { DULL, IN_WORD, IN_STRING } state = DULL;
+ const char *paramStart = nullptr;
+
+ argc = 0;
+ for (char *p = input; *p; ++p) {
+ c = (byte)*p;
+
+ switch (state) {
+ case DULL:
+ // not in a word, not in a double quoted string
+ if (isspace(c))
+ break;
+
+ // not a space -- if it's a double quote we go to IN_STRING, else to IN_WORD
+ if (c == '"') {
+ state = IN_STRING;
+ paramStart = p + 1; // word starts at *next* char, not this one
+ } else {
+ state = IN_WORD;
+ paramStart = p; // word starts here
+ }
+ break;
+
+ case IN_STRING:
+ // we're in a double quoted string, so keep going until we hit a close "
+ if (c == '"') {
+ // Add entire quoted string to parameter list
+ *p = '\0';
+ argv[argc++] = paramStart;
+ state = DULL; // back to "not in word, not in string" state
+ }
+ break;
+
+ case IN_WORD:
+ // we're in a word, so keep going until we get to a space
+ if (isspace(c)) {
+ *p = '\0';
+ argv[argc++] = paramStart;
+ state = DULL; // back to "not in word, not in string" state
+ }
+ break;
+ }
+ }
+
+ if (state != DULL)
+ // Add in final parameter
+ argv[argc++] = paramStart;
+}
+
// returns true if something has been completed
// completion has to be delete[]-ed then
bool Debugger::tabComplete(const char *input, Common::String &completion) const {
diff --git a/gui/debugger.h b/gui/debugger.h
index bc9306c1de..b12bd2761e 100644
--- a/gui/debugger.h
+++ b/gui/debugger.h
@@ -204,6 +204,12 @@ protected:
private:
void enter();
+ /**
+ * Splits up the input into individual parameters
+ * @remarks Adapted from code provided by torek on StackOverflow
+ */
+ void splitCommand(char *input, int &argc, const char **argv);
+
bool parseCommand(const char *input);
bool tabComplete(const char *input, Common::String &completion) const;