tb Command aliases, preloading scripts

This commit is contained in:
2025-09-19 19:55:35 +02:00
parent 24a90b24e8
commit 40b7dcedf8
6 changed files with 66 additions and 7 deletions

View File

@ -2,11 +2,13 @@
#include <stdbool.h>
#include <linklist.h>
#include <dlmalloc/malloc.h>
#include <string/string.h>
#include <uprintf.h>
#include "runtime.h"
#include "interp.h"
RtCmd *RTCMDS = NULL;
RtAlias *RTALIASES = NULL;
#define RTCMD(name, _fn) \
do { \
@ -29,6 +31,26 @@ bool rt_print(Token *tks) {
return true;
}
bool rt_mkalias(Token *tks) {
RtAlias *alias = dlmalloc(sizeof(*alias));
string_memset(alias, 0, sizeof(*alias));
Token *tk = tks;
size_t i = 0;
while (tk) {
if (i == 0) {
usprintf(alias->namebuf, "%.*s", (int)tk->len, tk->ptr);
} else {
size_t off = string_len(alias->valbuf);
usprintf(alias->valbuf + off, "%.*s", (int)tk->len, tk->ptr);
}
i++;
tk = tk->next;
}
LL_APPEND(RTALIASES, alias);
return true;
}
void rt_init(void) {
RTCMD("@print", &rt_print);
RTCMD("@mkalias", &rt_mkalias);
}