From 435edc801789fc454c2ad005fe63f875cc3dc5e9 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 10 Oct 2014 03:27:10 -0700 Subject: [PATCH] Prefix completion --- src/debugger/cli-debugger.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/debugger/cli-debugger.c b/src/debugger/cli-debugger.c index e2b06f47f..e1ad3f2ef 100644 --- a/src/debugger/cli-debugger.c +++ b/src/debugger/cli-debugger.c @@ -604,8 +604,25 @@ static unsigned char _tabComplete(EditLine* elstate, int ch) { if (!name) { return CC_ERROR; } - if (_debuggerCommands[cmd + 1].name && strncasecmp(_debuggerCommands[cmd + 1].name, li->buffer, len - 1) == 0) { - return CC_ERROR; + if (_debuggerCommands[cmd + 1].name && name[len - 2] == _debuggerCommands[cmd + 1].name[len - 2]) { + --len; + const char* next = 0; + int i; + for (i = cmd + 1; _debuggerCommands[i].name; ++i) { + if (strncasecmp(name, _debuggerCommands[i].name, len)) { + break; + } + next = _debuggerCommands[i].name; + } + + for (; name[len]; ++len) { + if (name[len] != next[len]) { + break; + } + char out[2] = { name[len], '\0' }; + el_insertstr(elstate, out); + } + return CC_REDISPLAY; } name += len - 1; el_insertstr(elstate, name);