ulib uprintf to pipe not termdev, ulib Add stringbuffer and linearlist, tb Capture subshell output

This commit is contained in:
2025-10-01 20:08:44 +02:00
parent 0e4a35eb86
commit 62cf07afc7
11 changed files with 210 additions and 13 deletions

View File

@ -10,13 +10,19 @@ PID_t PID;
struct {
char *modestr;
enum { MODE_INTERACTIVE = 1, MODE_RUNFILE = 2 } mode;
enum {
MODE_INTERACTIVE = 1,
MODE_RUNFILE = 2,
MODE_RUNSTRING = 3,
} mode;
char *filepath;
bool logcmds;
char *preloadpath;
char *runstring;
} CONFIG;
static Arg ARGS[] = {
@ -24,6 +30,7 @@ static Arg ARGS[] = {
ARG("-f", ARG_STRING, &CONFIG.filepath),
ARG("-logcmds", ARG_BOOL, &CONFIG.logcmds),
ARG("-preload", ARG_STRING, &CONFIG.preloadpath),
ARG("-rs", ARG_STRING, &CONFIG.runstring),
ARG_END(),
};
@ -40,6 +47,8 @@ void set_config(void) {
CONFIG.mode = MODE_INTERACTIVE;
} else if (string_strcmp(CONFIG.modestr, "runfile") == 0) {
CONFIG.mode = MODE_RUNFILE;
} else if (string_strcmp(CONFIG.modestr, "runstring") == 0) {
CONFIG.mode = MODE_RUNSTRING;
} else {
LOG(LOG_ERR, "Unknown mode %s\n", CONFIG.modestr);
}
@ -142,7 +151,6 @@ void main(void) {
set_config();
if (CONFIG.preloadpath != NULL) {
LOG(LOG_INF, "Preloading script: %s\n", CONFIG.preloadpath);
do_file(CONFIG.preloadpath);
}
@ -154,5 +162,21 @@ void main(void) {
return;
}
do_file(CONFIG.filepath);
} else if (CONFIG.mode == MODE_RUNSTRING) {
if (CONFIG.runstring == NULL) {
uprintf("Run string is empty\n");
return;
}
InterpResult *res;
if (CONFIG.runstring[0] == '\'') {
CONFIG.runstring[0] = ' ';
}
size_t len = string_len(CONFIG.runstring);
if (CONFIG.runstring[len] == '\'') {
CONFIG.runstring[len] = ' ';
}
if (!interp_runstring(CONFIG.runstring, &res, CONFIG.logcmds, false)) {
LOG(LOG_ERR, "%s\n", res->errmsg);
}
}
}