Remove % prefix for builtin commands

This commit is contained in:
2025-10-01 22:50:27 +02:00
parent 0232849994
commit 91d648ade4
5 changed files with 25 additions and 15 deletions

View File

@ -99,20 +99,23 @@ void tz_tokenize(Tokenizer *tz) {
}
void tz_classify(Tokenizer *tz) {
#define IF_RTCMD(name) if (string_strcmp(tk->str, #name) == 0) { \
tk->type = TOK_CMD; \
tk->cmd = &rt_ ## name; \
}
Token *tk, *tktmp;
LL_FOREACH_SAFE(tz->tokens, tk, tktmp) {
if (tk->str[0] == '\'') {
tk->type = TOK_STRING;
} else if (tk->str[0] == '%') {
RtCmd *cmd, *cmdtmp;
LL_FOREACH_SAFE(RTCMDS, cmd, cmdtmp) {
if (string_strcmp(tk->str, cmd->cmdname) == 0) {
tk->type = TOK_CMD;
tk->cmd = cmd;
break;
}
}
} else {
}
else IF_RTCMD(print)
else IF_RTCMD(mkalias)
else IF_RTCMD(PID)
else IF_RTCMD(do)
else IF_RTCMD(stackpush)
else IF_RTCMD(stackpop)
else {
tk->type = TOK_MISC;
}
}
@ -184,7 +187,7 @@ bool interp_runstring(char *string, InterpResult **res, bool logcmds, bool inter
Token *cmdtk = tz.tokens;
if (cmdtk->type == TOK_CMD) {
ok = cmdtk->cmd->fn(cmdtk->next);
ok = cmdtk->cmd(cmdtk->next);
if (!ok) {
usprintf(RES.errmsg, "cmd %s failed", cmdtk->str);
goto next;

View File

@ -21,7 +21,7 @@ typedef struct Token {
TOK_MISC,
} type;
struct RtCmd *cmd;
bool (*cmd)(struct Token *);
} Token;
typedef struct {

View File

@ -30,6 +30,13 @@ void rt_init(void);
extern RtCmd *RTCMDS;
extern RtAlias *RTALIASES;
bool rt_print(struct Token *);
bool rt_mkalias(struct Token *);
bool rt_PID(struct Token *);
bool rt_do(struct Token *);
bool rt_stackpush(struct Token *);
bool rt_stackpop(struct Token *);
void rtstringv_stackpushcopy(char *s, size_t len);
char *rtstringv_stackpop(void);
char *rtstringv_stackpeek(void);