diff --git a/user/init/main.c b/user/init/main.c index d9bf988..51a07f1 100644 --- a/user/init/main.c +++ b/user/init/main.c @@ -18,7 +18,7 @@ void main(void) { ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0); - char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb" }; + char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb", "-logcmds", "yes" }; int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs)); ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT); diff --git a/user/tb/interp.c b/user/tb/interp.c index 70e2999..4772935 100644 --- a/user/tb/interp.c +++ b/user/tb/interp.c @@ -150,7 +150,7 @@ bool interp_readline(char *data, const char **bgptr, const char **endptr) { return true; } -bool interp_runstring(const char *string, InterpResult **res) { +bool interp_runstring(const char *string, InterpResult **res, bool logcmds) { *res = &RES; string_memset(RES.errmsg, 0, sizeof(RES.errmsg)); @@ -160,6 +160,11 @@ bool interp_runstring(const char *string, InterpResult **res) { interp_readline((char *)string, NULL, NULL); while (interp_readline(NULL, &bg, &end)) { size_t linelen = end - bg; + + if (logcmds) { + uprintf("+ %.*s\n", (int)linelen, bg); + } + Tokenizer tz = {0}; tz_init(&tz, bg, linelen); diff --git a/user/tb/interp.h b/user/tb/interp.h index 01c5537..8c686d2 100644 --- a/user/tb/interp.h +++ b/user/tb/interp.h @@ -33,6 +33,6 @@ typedef struct { Token *tokens; } Tokenizer; -bool interp_runstring(const char *string, InterpResult **res); +bool interp_runstring(const char *string, InterpResult **res, bool logcmds); #endif // TB_INTERP_H_ diff --git a/user/tb/main.c b/user/tb/main.c index eb5034d..b8771fe 100644 --- a/user/tb/main.c +++ b/user/tb/main.c @@ -20,7 +20,10 @@ uint64_t PID; struct { char *modestr; enum { MODE_INTERACTIVE = 1, MODE_RUNFILE = 2 } mode; + char *filepath; + + bool logcmds; } CONFIG; #define LINEBUF_MAX 1024 @@ -28,6 +31,7 @@ struct { static Arg ARGS[] = { ARG("-m", ARG_STRING, &CONFIG.modestr), ARG("-f", ARG_STRING, &CONFIG.filepath), + ARG("-logcmds", ARG_BOOL, &CONFIG.logcmds), ARG_END(), }; @@ -79,7 +83,7 @@ void do_file(char *filepath) { } InterpResult *res; - bool ok = interp_runstring((const char *)buf, &res); + bool ok = interp_runstring((const char *)buf, &res, CONFIG.logcmds); if (!ok) { uprintf("Interpreter error:\n"); uprintf("%s\n", res->errmsg); @@ -109,7 +113,7 @@ void do_mode_interactive(void) { linebuf[cursor - 1] = '\0'; uprintf("\n"); InterpResult *res; - if (!interp_runstring(linebuf, &res)) { + if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) { LOG(LOG_ERR, "%s\n", res->errmsg); } }