tb Command aliases, preloading scripts
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user