[Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.19,1.20
Max Horn
fingolfin at users.sourceforge.net
Mon Dec 16 14:26:04 CET 2002
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv13654
Modified Files:
console.cpp
Log Message:
fix Ctrl-D; work around VC++ quirks properly
Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- console.cpp 16 Dec 2002 22:15:38 -0000 1.19
+++ console.cpp 16 Dec 2002 22:25:54 -0000 1.20
@@ -153,22 +153,34 @@
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 @@
draw();
break;
case 'd':
- killChar();
- draw();
+ if (_currentPos < _promptEndPos) {
+ killChar();
+ draw();
+ }
break;
case 'e':
_currentPos = _promptEndPos;
More information about the Scummvm-git-logs
mailing list