aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2002-12-16 22:25:54 +0000
committerMax Horn2002-12-16 22:25:54 +0000
commit27f896deca47076fa074934f796c2e1211915c6e (patch)
treea1ff72e8cc24f0c985a75420a679775dea9232d4 /gui
parente3bfb6f1feda36582432ade63ba83e9e38e3b71e (diff)
downloadscummvm-rg350-27f896deca47076fa074934f796c2e1211915c6e.tar.gz
scummvm-rg350-27f896deca47076fa074934f796c2e1211915c6e.tar.bz2
scummvm-rg350-27f896deca47076fa074934f796c2e1211915c6e.zip
fix Ctrl-D; work around VC++ quirks properly
svn-id: r6003
Diffstat (limited to 'gui')
-rw-r--r--gui/console.cpp44
1 files changed, 29 insertions, 15 deletions
diff --git a/gui/console.cpp b/gui/console.cpp
index 73eba7ca72..97984fd7c4 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -153,22 +153,34 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
nextLine();
int len = _promptEndPos - _promptStartPos;
-// char str[len + 1];
- char str[1000];
-
- if (len < 0) len = 0; // Prevent overflow from forced Ctrl-D deletion
+ bool keepRunning = true;
- for (i = 0; i < len; i++)
- str[i] = _buffer[(_promptStartPos + i) % kBufferSize];
- str[len] = '\0';
+ // FIXME - len should NEVER be negative. If anything makes it negative,
+ // then the code doing that is buggy and needs to be fixed.
+ assert(len >= 0);
- addToHistory(str);
-
- bool keepRunning = true;
- if (_callbackProc)
- keepRunning = (*_callbackProc)(this, str, _callbackRefCon);
- //printf("You entered '%s'\n", str);
+ if (len > 0) {
+ // We have to allocate the string buffer with new, since VC++ sadly does not
+ // comply to the C++ standard, so we can't use a dynamic sized stack array.
+ char *str = new char[len + 1];
+
+ // Copy the user intput to str
+ for (i = 0; i < len; i++)
+ str[i] = _buffer[(_promptStartPos + i) % kBufferSize];
+ str[len] = '\0';
+
+ // Add the input to the history
+ addToHistory(str);
+
+ // Pass it to the input callback, if any
+ if (_callbackProc)
+ keepRunning = (*_callbackProc)(this, str, _callbackRefCon);
+
+ // Get rid of the string buffer
+ delete [] str;
+ }
+
print(PROMPT);
_promptStartPos = _promptEndPos = _currentPos;
@@ -270,8 +282,10 @@ void ConsoleDialog::specialKeys(int keycode)
draw();
break;
case 'd':
- killChar();
- draw();
+ if (_currentPos < _promptEndPos) {
+ killChar();
+ draw();
+ }
break;
case 'e':
_currentPos = _promptEndPos;