Removed console aliases
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
#include "input/input.h"
|
||||
#include "util/string.h"
|
||||
|
||||
void cmdAlias(const consolecmdexec_t *exec) {
|
||||
if(exec->argc < 1) {
|
||||
consolePrint("Expected 1 argument: <name> <command>");
|
||||
return;
|
||||
}
|
||||
|
||||
if(exec->argc == 1 || strlen(exec->argv[1]) == 0) {
|
||||
// Removing the alias.
|
||||
for(uint32_t i = 0; i < CONSOLE.aliasCount; i++) {
|
||||
if(stringCompare(CONSOLE.aliases[i].alias, exec->argv[0]) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move all the later aliases down one.
|
||||
if(CONSOLE.aliasCount - i - 1 > 0) {
|
||||
memoryMove(
|
||||
&CONSOLE.aliases[i],
|
||||
&CONSOLE.aliases[i + 1],
|
||||
(CONSOLE.aliasCount - i - 1) * sizeof(consolealias_t)
|
||||
);
|
||||
}
|
||||
CONSOLE.aliasCount--;
|
||||
return;
|
||||
}
|
||||
|
||||
// Alias not found.
|
||||
return;
|
||||
}
|
||||
|
||||
// Add alias
|
||||
if(CONSOLE.aliasCount >= CONSOLE_ALIAS_MAX) {
|
||||
consolePrint("Max aliases reached");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create alias
|
||||
consolealias_t *alias = &CONSOLE.aliases[CONSOLE.aliasCount++];
|
||||
stringCopy(alias->alias, exec->argv[0], CONSOLE_LINE_MAX);
|
||||
stringCopy(alias->command, exec->argv[1], CONSOLE_LINE_MAX);
|
||||
consolePrint("Added alias \"%s\" -> \"%s\"", exec->argv[0], exec->argv[1]);
|
||||
}
|
||||
@@ -14,5 +14,5 @@ void cmdEcho(const consolecmdexec_t *exec) {
|
||||
return;
|
||||
}
|
||||
|
||||
consolePrint("%s\n", exec->argv[0]);
|
||||
consolePrint("%s", exec->argv[0]);
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "console/cmd/cmdquit.h"
|
||||
// #include "console/cmd/cmdbind.h"
|
||||
// #include "console/cmd/cmdtoggleconsole.h"
|
||||
// #include "console/cmd/cmdalias.h"
|
||||
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "display/text/text.h"
|
||||
@@ -36,8 +35,12 @@ void consoleInit() {
|
||||
// Register cmds
|
||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
||||
consoleRegCmd("echo", cmdEcho);
|
||||
consoleRegCmd("quit", cmdQuit);
|
||||
|
||||
#define REG(name, func) consoleRegCmd(name, func)
|
||||
REG("echo", cmdEcho);
|
||||
REG("quit", cmdQuit);
|
||||
REG("exit", cmdQuit);
|
||||
#undef REG
|
||||
|
||||
#ifdef DUSK_CONSOLE_POSIX
|
||||
threadInit(&CONSOLE.thread, consoleInputThread);
|
||||
@@ -114,7 +117,7 @@ void consolePrint(const char_t *message, ...) {
|
||||
threadMutexUnlock(&CONSOLE.printMutex);
|
||||
#endif
|
||||
|
||||
logDebug("%s", buffer);
|
||||
logDebug("%s\n", buffer);
|
||||
}
|
||||
|
||||
void consoleExec(const char_t *line) {
|
||||
@@ -307,33 +310,6 @@ void consoleExec(const char_t *line) {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
char_t aliasCmd[CONSOLE_LINE_MAX];
|
||||
stringCopy(aliasCmd, alias->command, CONSOLE_LINE_MAX);
|
||||
|
||||
// Null exec before unlocking so the unclaimed slot cannot be
|
||||
// raced by another thread calling consoleExec concurrently.
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
aliasFound = true;
|
||||
|
||||
#ifdef DUSK_CONSOLE_POSIX
|
||||
threadMutexUnlock(&CONSOLE.execMutex);
|
||||
#endif
|
||||
consoleExec(aliasCmd);
|
||||
#ifdef DUSK_CONSOLE_POSIX
|
||||
threadMutexLock(&CONSOLE.execMutex);
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(!aliasFound) {
|
||||
stringFormat(
|
||||
pendingPrint, CONSOLE_LINE_MAX,
|
||||
"Command \"%s\" not found", exec->command
|
||||
@@ -341,8 +317,6 @@ void consoleExec(const char_t *line) {
|
||||
exec = NULL;
|
||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Prep for next command.
|
||||
exec = NULL;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#pragma once
|
||||
#include "consolevar.h"
|
||||
#include "consolecmd.h"
|
||||
#include "consolealias.h"
|
||||
#include "error/error.h"
|
||||
|
||||
#ifdef DUSK_CONSOLE_POSIX
|
||||
@@ -44,9 +43,6 @@ typedef struct {
|
||||
consolecmdexec_t execBuffer[CONSOLE_EXEC_BUFFER_MAX];
|
||||
uint32_t execBufferCount;
|
||||
|
||||
consolealias_t aliases[CONSOLE_ALIAS_MAX];
|
||||
uint32_t aliasCount;
|
||||
|
||||
consolecmd_t *cmdGet;
|
||||
consolecmd_t *cmdSet;
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "consolecmd.h"
|
||||
|
||||
typedef struct {
|
||||
char_t command[CONSOLE_LINE_MAX];
|
||||
char_t alias[CONSOLE_LINE_MAX];
|
||||
} consolealias_t;
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define CONSOLE_CMD_NAME_MAX 32
|
||||
#define CONSOLE_CMD_NAME_MAX 16
|
||||
#define CONSOLE_CMD_ARGC_MAX 16
|
||||
|
||||
#define CONSOLE_COMMANDS_MAX 32
|
||||
|
||||
@@ -47,7 +47,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
physicsManagerInit();
|
||||
errorChain(networkInit());
|
||||
errorChain(gameInit());
|
||||
consolePrint("Engine initialized\n");
|
||||
consolePrint("Engine initialized");
|
||||
|
||||
/* Run the init script. */
|
||||
scriptcontext_t ctx;
|
||||
|
||||
@@ -20,7 +20,7 @@ void entityManagerInit(void) {
|
||||
);
|
||||
|
||||
consolePrint(
|
||||
"Entity Manager size: %zu bytes (%.2f KB)\n",
|
||||
"Entity Manager size: %zu bytes (%.2f KB)",
|
||||
sizeof(entitymanager_t),
|
||||
sizeof(entitymanager_t) / 1024.0f
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user