Parse commandline strings, move away from old env vars
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m6s
Build documentation / build-and-deploy (push) Successful in 1m18s

This commit is contained in:
2026-04-28 22:45:31 +02:00
parent 9fbe23024c
commit fbf067d418
15 changed files with 265 additions and 185 deletions

44
ce/ce.c
View File

@@ -3,6 +3,7 @@
#include "interp.h"
#include "strbuf.h"
#include <arena.h>
#include <cmdline_parser.h>
#include <debugconsole.h>
#include <filereader.h>
#include <in_gb.h>
@@ -22,7 +23,16 @@
#define PROMPT "$ "
bool print_commands = false;
static bool cmdline_printcmds = false;
static char cmdline_script[CMDLINE_OPT_VALUE_MAX];
static char cmdline_posvars[CMDLINE_OPT_VALUE_MAX];
static struct cmdline_opt cmdline_opts[] = {
CMDLINE_OPT("p", "printcmds", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_printcmds),
CMDLINE_OPT("s", "script", CMDLINE_OPT_VALUE_STRING, false, (char*)cmdline_script),
CMDLINE_OPT("a", "args", CMDLINE_OPT_VALUE_STRING, false, (char*)cmdline_posvars),
CMDLINE_END(),
};
void* wmalloc(void* ctx, size_t size) {
(void)ctx;
@@ -59,7 +69,7 @@ struct edit_line {
static void exec_line(const char* line) {
struct list_node_link* tokens = NULL;
if (print_commands)
if (cmdline_printcmds)
mprintf("+%s\n", line);
tokenize(&tokens, line);
@@ -98,35 +108,23 @@ static bool split_args_cb(void* ctx, const char* start, size_t len) {
}
void app_main(void) {
char scriptpathbuf[PATH_MAX];
char posvarsbuf[2048];
char printcmdsbuf[4];
char line[1024];
const char* cmdline = get_cmdline();
debug_printf("cmdline=\"%s\"\n", cmdline);
if (env_get(process_get_pgid(), "printcmds", (void*)printcmdsbuf, sizeof(printcmdsbuf)) ==
ST_OK &&
strcmp(printcmdsbuf, "yes") == 0) {
print_commands = true;
if (cmdline_parse(get_cmdline(), cmdline_opts) < 0) {
mprintf("Failed to parse commandline arguments\n");
return;
}
memset(scriptpathbuf, 0, sizeof(scriptpathbuf));
int has_script = env_get(process_get_pgid(), "s", (void*)scriptpathbuf, sizeof(scriptpathbuf));
char line[1024];
if (has_script == ST_OK) {
if (env_get(process_get_pgid(), "args", (void*)posvarsbuf, sizeof(posvarsbuf)) == ST_OK) {
strtokenize(posvarsbuf, ' ', NULL, &split_args_cb);
}
if (strlen(cmdline_script) > 0) {
if (strlen(cmdline_posvars) > 0)
strtokenize(cmdline_posvars, ' ', NULL, &split_args_cb);
char volume[VOLUME_MAX];
const char* path;
int ret;
if (!path_parse(scriptpathbuf, volume, &path)) {
mprintf("ERROR bad path '%s'\n", scriptpathbuf);
if (!path_parse(cmdline_script, volume, &path)) {
mprintf("ERROR bad path '%s'\n", cmdline_script);
return;
}