tb implement command logging
This commit is contained in:
@ -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);
|
||||
|
||||
|
@ -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_
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user