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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
consolePrint("%s\n", exec->argv[0]);
|
consolePrint("%s", exec->argv[0]);
|
||||||
}
|
}
|
||||||
+13
-39
@@ -19,7 +19,6 @@
|
|||||||
#include "console/cmd/cmdquit.h"
|
#include "console/cmd/cmdquit.h"
|
||||||
// #include "console/cmd/cmdbind.h"
|
// #include "console/cmd/cmdbind.h"
|
||||||
// #include "console/cmd/cmdtoggleconsole.h"
|
// #include "console/cmd/cmdtoggleconsole.h"
|
||||||
// #include "console/cmd/cmdalias.h"
|
|
||||||
|
|
||||||
#include "display/shader/shaderunlit.h"
|
#include "display/shader/shaderunlit.h"
|
||||||
#include "display/text/text.h"
|
#include "display/text/text.h"
|
||||||
@@ -36,8 +35,12 @@ void consoleInit() {
|
|||||||
// Register cmds
|
// Register cmds
|
||||||
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
CONSOLE.cmdGet = consoleRegCmd("get", cmdGet);
|
||||||
CONSOLE.cmdSet = consoleRegCmd("set", cmdSet);
|
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
|
#ifdef DUSK_CONSOLE_POSIX
|
||||||
threadInit(&CONSOLE.thread, consoleInputThread);
|
threadInit(&CONSOLE.thread, consoleInputThread);
|
||||||
@@ -114,7 +117,7 @@ void consolePrint(const char_t *message, ...) {
|
|||||||
threadMutexUnlock(&CONSOLE.printMutex);
|
threadMutexUnlock(&CONSOLE.printMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
logDebug("%s", buffer);
|
logDebug("%s\n", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void consoleExec(const char_t *line) {
|
void consoleExec(const char_t *line) {
|
||||||
@@ -307,41 +310,12 @@ void consoleExec(const char_t *line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(exec->cmd == NULL) {
|
if(exec->cmd == NULL) {
|
||||||
// Variable not found, is there an alias that matches?
|
stringFormat(
|
||||||
bool_t aliasFound = false;
|
pendingPrint, CONSOLE_LINE_MAX,
|
||||||
for(uint32_t k = 0; k < CONSOLE.aliasCount; k++) {
|
"Command \"%s\" not found", exec->command
|
||||||
consolealias_t *alias = &CONSOLE.aliases[k];
|
);
|
||||||
if(stringCompare(alias->alias, exec->command) != 0) continue;
|
exec = NULL;
|
||||||
|
state = CONSOLE_EXEC_STATE_INITIAL;
|
||||||
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
|
|
||||||
);
|
|
||||||
exec = NULL;
|
|
||||||
state = CONSOLE_EXEC_STATE_INITIAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prep for next command.
|
// Prep for next command.
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "consolevar.h"
|
#include "consolevar.h"
|
||||||
#include "consolecmd.h"
|
#include "consolecmd.h"
|
||||||
#include "consolealias.h"
|
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
|
|
||||||
#ifdef DUSK_CONSOLE_POSIX
|
#ifdef DUSK_CONSOLE_POSIX
|
||||||
@@ -44,9 +43,6 @@ typedef struct {
|
|||||||
consolecmdexec_t execBuffer[CONSOLE_EXEC_BUFFER_MAX];
|
consolecmdexec_t execBuffer[CONSOLE_EXEC_BUFFER_MAX];
|
||||||
uint32_t execBufferCount;
|
uint32_t execBufferCount;
|
||||||
|
|
||||||
consolealias_t aliases[CONSOLE_ALIAS_MAX];
|
|
||||||
uint32_t aliasCount;
|
|
||||||
|
|
||||||
consolecmd_t *cmdGet;
|
consolecmd_t *cmdGet;
|
||||||
consolecmd_t *cmdSet;
|
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
|
#pragma once
|
||||||
|
|
||||||
#define CONSOLE_CMD_NAME_MAX 32
|
#define CONSOLE_CMD_NAME_MAX 16
|
||||||
#define CONSOLE_CMD_ARGC_MAX 16
|
#define CONSOLE_CMD_ARGC_MAX 16
|
||||||
|
|
||||||
#define CONSOLE_COMMANDS_MAX 32
|
#define CONSOLE_COMMANDS_MAX 32
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
|||||||
physicsManagerInit();
|
physicsManagerInit();
|
||||||
errorChain(networkInit());
|
errorChain(networkInit());
|
||||||
errorChain(gameInit());
|
errorChain(gameInit());
|
||||||
consolePrint("Engine initialized\n");
|
consolePrint("Engine initialized");
|
||||||
|
|
||||||
/* Run the init script. */
|
/* Run the init script. */
|
||||||
scriptcontext_t ctx;
|
scriptcontext_t ctx;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ void entityManagerInit(void) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
consolePrint(
|
consolePrint(
|
||||||
"Entity Manager size: %zu bytes (%.2f KB)\n",
|
"Entity Manager size: %zu bytes (%.2f KB)",
|
||||||
sizeof(entitymanager_t),
|
sizeof(entitymanager_t),
|
||||||
sizeof(entitymanager_t) / 1024.0f
|
sizeof(entitymanager_t) / 1024.0f
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user