Command aliasing
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "console/cmd/cmdexec.h"
|
||||
#include "console/cmd/cmdbind.h"
|
||||
#include "console/cmd/cmdtoggleconsole.h"
|
||||
#include "console/cmd/cmdalias.h"
|
||||
|
||||
console_t CONSOLE;
|
||||
|
||||
@@ -32,6 +33,7 @@ void consoleInit() {
|
||||
consoleRegCmd("exec", cmdExec);
|
||||
consoleRegCmd("bind", cmdBind);
|
||||
consoleRegCmd("toggleconsole", cmdToggleConsole);
|
||||
consoleRegCmd("alias", cmdAlias);
|
||||
|
||||
#if CONSOLE_POSIX
|
||||
threadInit(&CONSOLE.thread, consoleInputThread);
|
||||
@@ -286,14 +288,34 @@ void consoleExec(const char_t *line) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(exec->cmd == NULL) {
|
||||
// Variable not found, is there an alias that matches?
|
||||
bool_t aliasFound = false;
|
||||
for(uint32_t k = 0; k < CONSOLE.aliasCount; k++) {
|
||||
consolealias_t *alias = &CONSOLE.aliases[k];
|
||||
if(stringCompare(alias->alias, exec->command) != 0) continue;
|
||||
|
||||
// Matching alias found, we unlock the mutex and recursively call
|
||||
// consoleExec to handle the alias command.
|
||||
#if CONSOLE_POSIX
|
||||
threadMutexUnlock(&CONSOLE.execMutex);
|
||||
#endif
|
||||
consoleExec(alias->command);
|
||||
#if CONSOLE_POSIX
|
||||
threadMutexLock(&CONSOLE.execMutex);
|
||||
#endif
|
||||
|
||||
aliasFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!aliasFound && exec->cmd == NULL) {
|
||||
consolePrint("Command \"%s\" not found", exec->command);
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Prep for next command.
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
|
Reference in New Issue
Block a user