Ticket #8211: debugger_completion.diff
File debugger_completion.diff, 6.4 KB (added by , 22 years ago) |
---|
-
gui/console.cpp
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v retrieving revision 1.24 diff -u -r1.24 console.cpp
159 159 // comply to the C++ standard, so we can't use a dynamic sized stack array. 160 160 char *str = new char[len + 1]; 161 161 162 // Copy the user in tput to str162 // Copy the user input to str 163 163 for (i = 0; i < len; i++) 164 164 str[i] = _buffer[(_promptStartPos + i) % kBufferSize]; 165 165 str[len] = '\0'; … … 197 197 scrollToCurrent(); 198 198 draw(); // FIXME - not nice to redraw the full console just for one char! 199 199 break; 200 case 9: // tab 201 { 202 if (_completionCallbackProc) { 203 int len = _currentPos - _promptStartPos; 204 assert(len >= 0); 205 char *str = new char[len + 1]; 206 207 // Copy the user input to str 208 for (i = 0; i < len; i++) 209 str[i] = _buffer[(_promptStartPos + i) % kBufferSize]; 210 str[len] = '\0'; 211 212 char *completion = 0; 213 if ((*_completionCallbackProc)(this, str, completion, 214 _callbackRefCon)) 215 { 216 if (_caretVisible) 217 drawCaret(true); 218 insertIntoPrompt(completion); 219 scrollToCurrent(); 220 draw(); 221 delete[] completion; 222 } 223 delete[] str; 224 } 225 break; 226 } 200 227 case 127: 201 228 killChar(); 202 229 draw(); … … 252 279 putchar((char)ascii); 253 280 scrollToCurrent(); 254 281 } 282 } 283 } 284 285 void ConsoleDialog::insertIntoPrompt(const char* str) 286 { 287 unsigned int l = strlen(str); 288 for (int i = _promptEndPos-1; i >= _currentPos; i--) 289 _buffer[(i + l) % kBufferSize] = 290 _buffer[i % kBufferSize]; 291 for (unsigned int j = 0; j < l; ++j) { 292 _promptEndPos++; 293 putcharIntern(str[j]); 255 294 } 256 295 } 257 296 -
gui/console.h
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v retrieving revision 1.15 diff -u -r1.15 console.h
39 39 class ConsoleDialog : public Dialog { 40 40 public: 41 41 typedef bool (*InputCallbackProc)(ConsoleDialog *console, const char *input, void *refCon); 42 typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon); 42 43 43 44 protected: 44 45 char _buffer[kBufferSize]; … … 63 64 InputCallbackProc _callbackProc; 64 65 void *_callbackRefCon; 65 66 67 // _completionCallbackProc is called when tab is pressed 68 CompletionCallbackProc _completionCallbackProc; 69 void *_completionCallbackRefCon; 70 66 71 char _history[kHistorySize][kLineBufferSize]; 67 72 int _historySize; 68 73 int _historyIndex; … … 88 93 _callbackProc = proc; 89 94 _callbackRefCon = refCon; 90 95 } 96 void setCompletionCallback(CompletionCallbackProc proc, void *refCon) { 97 _completionCallbackProc = proc; 98 _completionCallbackRefCon = refCon; 99 } 91 100 92 101 protected: 93 102 void drawCaret(bool erase); 94 103 void putcharIntern(int c); 104 void insertIntoPrompt(const char *str); 95 105 void print(const char *str); 96 106 void nextLine(); 97 107 void updateScrollBar(); -
scumm/debugger.cpp
RCS file: /cvsroot/scummvm/scummvm/scumm/debugger.cpp,v retrieving revision 1.29 diff -u -r1.29 debugger.cpp
107 107 108 108 void ScummDebugger::detach() { 109 109 #ifdef USE_CONSOLE 110 if (_s->_debuggerDialog) 110 if (_s->_debuggerDialog) { 111 111 _s->_debuggerDialog->setInputeCallback(0, 0); 112 _s->_debuggerDialog->setCompletionCallback(0, 0); 113 } 112 114 #endif 113 115 114 116 _s->_debugger = NULL; … … 144 146 145 147 return debugger->RunCommand((char*)input); 146 148 } 149 150 151 bool ScummDebugger::debuggerCompletionCallback(ConsoleDialog *console, const char *input, char*& completion, void *refCon) { 152 ScummDebugger *debugger = (ScummDebugger *)refCon; 153 154 return debugger->TabComplete(input, completion); 155 } 156 147 157 #endif 148 158 149 159 /////////////////////////////////////////////////// … … 184 194 } 185 195 186 196 _s->_debuggerDialog->setInputeCallback(debuggerInputCallback, this); 197 _s->_debuggerDialog->setCompletionCallback(debuggerCompletionCallback, 198 this); 187 199 _s->_debuggerDialog->runModal(); 188 200 #else 189 201 printf("Debugger entered, please switch to this console for input.\n"); … … 783 795 784 796 return true; 785 797 } 798 799 // returns true if something has been completed 800 // completion has to be delete[]-ed then 801 bool ScummDebugger::TabComplete(const char *input, char*& completion) { 802 // very basic tab completion 803 // for now it just supports command completions 804 805 // adding completions of command parameters would be nice (but hard) :-) 806 // maybe also give a list of possible command completions? 807 // (but this will require changes to console) 808 809 if (strchr(input, ' ')) 810 return false; // already finished the first word 811 812 unsigned int inputlen = strlen(input); 813 814 unsigned int matchlen = 0; 815 char match[30]; // the max. command name is 30 chars 816 817 for(int i=0; i < _dcmd_count; i++) { 818 if (!strncmp(_dcmds[i].name, input, inputlen)) { 819 unsigned int commandlen = strlen(_dcmds[i].name); 820 if (commandlen == inputlen) { // perfect match 821 return false; 822 } 823 if (commandlen > inputlen) { // possible match 824 // no previous match 825 if (matchlen == 0) { 826 strcpy(match, _dcmds[i].name + inputlen); 827 matchlen = commandlen - inputlen; 828 } else { 829 // take common prefix of previous match and this command 830 unsigned int j; 831 for (j = 0; j < matchlen; j++) { 832 if (match[j] != _dcmds[i].name[inputlen + j]) break; 833 } 834 matchlen = j; 835 } 836 } 837 } 838 } 839 if (matchlen == 0) 840 return false; 841 842 completion = new char[matchlen+1]; 843 memcpy(completion, match, matchlen); 844 completion[matchlen+1] = 0; 845 return true; 846 } 847 -
scumm/debugger.h
RCS file: /cvsroot/scummvm/scummvm/scumm/debugger.h,v retrieving revision 1.18 diff -u -r1.18 debugger.h
96 96 97 97 #ifdef USE_CONSOLE 98 98 static bool debuggerInputCallback(ConsoleDialog *console, const char *input, void *refCon); 99 static bool debuggerCompletionCallback(ConsoleDialog *console, const char *input, char*& completion, void *refCon); 99 100 #endif 101 102 bool TabComplete(const char *input, char*& completion); 103 100 104 }; 101 105 102 106 #endif