Add exec command

This commit is contained in:
2025-09-07 23:24:21 -05:00
parent 3f37b7cdb5
commit e32d1f0900
16 changed files with 249 additions and 18 deletions

View File

@@ -13,6 +13,7 @@
#include "console/cmd/cmdecho.h"
#include "console/cmd/cmdset.h"
#include "console/cmd/cmdget.h"
#include "console/cmd/cmdexec.h"
#include "input/input.h"
console_t CONSOLE;
@@ -25,6 +26,7 @@ void consoleInit() {
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
consoleRegCmd("quit", cmdQuit);
consoleRegCmd("echo", cmdEcho);
consoleRegCmd("exec", cmdExec);
consolePrint(" = Dawn Console = ");
@@ -316,19 +318,36 @@ void consoleUpdate() {
CONSOLE.visible = !CONSOLE.visible;
}
// Exec pending buffer.
for(uint32_t i = 0; i < CONSOLE.execBufferCount; i++) {
consolecmdexec_t *exec = &CONSOLE.execBuffer[i];
assertNotNull(exec->cmd, "Command execution has no command.");
exec->cmd->function(exec);
// Anything to exec?
if(CONSOLE.execBufferCount == 0) {
#if CONSOLE_POSIX
threadMutexUnlock(&CONSOLE.execMutex);
#endif
return;
}
// Clear the exec buffer
CONSOLE.execBufferCount = 0;
// Copy the exec buffer, this allows exec command to work
consolecmdexec_t execBuffer[CONSOLE_EXEC_BUFFER_MAX];
uint32_t execBufferCount = CONSOLE.execBufferCount;
memoryCopy(
execBuffer,
CONSOLE.execBuffer,
sizeof(consolecmdexec_t) * execBufferCount
);
// Clear the exec buffer and unlock so new commands can be added while we
// process the current ones.
CONSOLE.execBufferCount = 0;
#if CONSOLE_POSIX
threadMutexUnlock(&CONSOLE.execMutex);
#endif
// Exec pending buffer.
for(uint32_t i = 0; i < execBufferCount; i++) {
consolecmdexec_t *exec = &execBuffer[i];
assertNotNull(exec->cmd, "Command execution has no command.");
exec->cmd->function(exec);
}
}
void consoleDispose(void) {