tb Enable/disable command logging dynamically + setlogcmds builtin

This commit is contained in:
2025-10-18 10:48:31 +02:00
parent d136c001df
commit a46da0a7ae
6 changed files with 56 additions and 21 deletions

View File

@ -3,26 +3,14 @@
#include <ulib.h>
#include "interp.h"
#include "macros.h"
#include "config.h"
#define LINEBUF_MAX 1024
PID_t PID;
Dev_t ps2kbdev;
struct {
char *modestr;
enum {
MODE_INTERACTIVE = 1,
MODE_RUNFILE = 2,
MODE_RUNSTRING = 3,
} mode;
char *filepath;
bool logcmds;
char *runstring;
} CONFIG;
Config CONFIG;
static Arg ARGS[] = {
ARG("-m", ARG_STRING, &CONFIG.modestr),
@ -78,7 +66,7 @@ void do_file(char *filepath) {
}
InterpResult *res;
bool ok = interp_runstring((char *)buf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE);
bool ok = interp_runstring((char *)buf, &res, CONFIG.mode == MODE_INTERACTIVE);
if (!ok) {
uprintf("Interpreter error:\n");
uprintf("%s\n", res->errmsg);
@ -137,7 +125,7 @@ void do_mode_interactive(void) {
uprintf(ANSIQ_GR_RESET);
uprintf("\n");
InterpResult *res;
if (!interp_runstring(linebuf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE)) {
if (!interp_runstring(linebuf, &res, CONFIG.mode == MODE_INTERACTIVE)) {
LOG(LOG_ERR, "%s\n", res->errmsg);
}
}
@ -173,7 +161,7 @@ void main(void) {
if (CONFIG.runstring[len] == '\'') {
CONFIG.runstring[len] = ' ';
}
if (!interp_runstring(CONFIG.runstring, &res, CONFIG.logcmds, false)) {
if (!interp_runstring(CONFIG.runstring, &res, false)) {
LOG(LOG_ERR, "%s\n", res->errmsg);
}
}