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

@ -13,8 +13,6 @@
#include "interp.h"
#include "runtime.h"
/* #define SUBPROC_PIPE_OUT 31 */
extern uint64_t PID;
static InterpResult RES;
@ -98,6 +96,27 @@ void tz_classify(Tokenizer *tz) {
dlfree(tmpbuf);
}
void tz_expandspecial(Tokenizer *tz) {
Token *tk = tz->tokens;
while (tk) {
if (tk->ptr[0] == '$' && tk->len > 1) {
char *aliasbuf = dlmalloc(RTALIAS_NAMEBUF_MAX);
usnprintf(aliasbuf, RTALIAS_NAMEBUF_MAX, "%.*s", (int)tk->len-1, &tk->ptr[1]);
RtAlias *alias = RTALIASES;
while (alias) {
if (string_strcmp(alias->namebuf, aliasbuf) == 0) {
tk->ptr = alias->valbuf;
tk->len = string_len(alias->valbuf);
break;
}
alias = alias->next;
}
dlfree(aliasbuf);
}
tk = tk->next;
}
}
bool interp_readline(char *data, const char **bgptr, const char **endptr) {
static char *nextstart;
if (data) {
@ -178,6 +197,7 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
}
tz_classify(&tz);
tz_expandspecial(&tz);
Token *cmdtk = tz.tokens;
if (cmdtk->type == TOK_CMD) {