tb implement command logging

This commit is contained in:
2025-09-17 22:07:58 +02:00
parent ac1cc172f7
commit ba1c0eedbd
4 changed files with 14 additions and 5 deletions

View File

@ -18,7 +18,7 @@ void main(void) {
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0); 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)); 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); ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT);

View File

@ -150,7 +150,7 @@ bool interp_readline(char *data, const char **bgptr, const char **endptr) {
return true; return true;
} }
bool interp_runstring(const char *string, InterpResult **res) { bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
*res = &RES; *res = &RES;
string_memset(RES.errmsg, 0, sizeof(RES.errmsg)); 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); interp_readline((char *)string, NULL, NULL);
while (interp_readline(NULL, &bg, &end)) { while (interp_readline(NULL, &bg, &end)) {
size_t linelen = end - bg; size_t linelen = end - bg;
if (logcmds) {
uprintf("+ %.*s\n", (int)linelen, bg);
}
Tokenizer tz = {0}; Tokenizer tz = {0};
tz_init(&tz, bg, linelen); tz_init(&tz, bg, linelen);

View File

@ -33,6 +33,6 @@ typedef struct {
Token *tokens; Token *tokens;
} Tokenizer; } Tokenizer;
bool interp_runstring(const char *string, InterpResult **res); bool interp_runstring(const char *string, InterpResult **res, bool logcmds);
#endif // TB_INTERP_H_ #endif // TB_INTERP_H_

View File

@ -20,7 +20,10 @@ uint64_t PID;
struct { struct {
char *modestr; char *modestr;
enum { MODE_INTERACTIVE = 1, MODE_RUNFILE = 2 } mode; enum { MODE_INTERACTIVE = 1, MODE_RUNFILE = 2 } mode;
char *filepath; char *filepath;
bool logcmds;
} CONFIG; } CONFIG;
#define LINEBUF_MAX 1024 #define LINEBUF_MAX 1024
@ -28,6 +31,7 @@ struct {
static Arg ARGS[] = { static Arg ARGS[] = {
ARG("-m", ARG_STRING, &CONFIG.modestr), ARG("-m", ARG_STRING, &CONFIG.modestr),
ARG("-f", ARG_STRING, &CONFIG.filepath), ARG("-f", ARG_STRING, &CONFIG.filepath),
ARG("-logcmds", ARG_BOOL, &CONFIG.logcmds),
ARG_END(), ARG_END(),
}; };
@ -79,7 +83,7 @@ void do_file(char *filepath) {
} }
InterpResult *res; InterpResult *res;
bool ok = interp_runstring((const char *)buf, &res); bool ok = interp_runstring((const char *)buf, &res, CONFIG.logcmds);
if (!ok) { if (!ok) {
uprintf("Interpreter error:\n"); uprintf("Interpreter error:\n");
uprintf("%s\n", res->errmsg); uprintf("%s\n", res->errmsg);
@ -109,7 +113,7 @@ void do_mode_interactive(void) {
linebuf[cursor - 1] = '\0'; linebuf[cursor - 1] = '\0';
uprintf("\n"); uprintf("\n");
InterpResult *res; InterpResult *res;
if (!interp_runstring(linebuf, &res)) { if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) {
LOG(LOG_ERR, "%s\n", res->errmsg); LOG(LOG_ERR, "%s\n", res->errmsg);
} }
} }