#include #include #include #include "runtime.h" #include "interp.h" RtCmd *RTCMDS = NULL; RtAlias *RTALIASES = NULL; #define RTCMD(name, _fn) \ do { \ RtCmd *_cmd = dlmalloc(sizeof(*_cmd)); \ _cmd->cmdname = (name); \ _cmd->fn = (_fn); \ LL_APPEND(RTCMDS, _cmd); \ } while(0) bool rt_print(Token *tks) { Token *tk = tks; while (tk) { uprintf("%.*s", (int)tk->len, tk->ptr); if (tk->next != NULL) { uprintf(" "); } tk = tk->next; } uprintf("\n"); 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 if (i == 1) { usprintf(alias->valbuf, "%.*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); }