This commit is contained in:
2025-09-27 15:16:26 +02:00
parent 5af7c5276a
commit 3b1bb9d531
63 changed files with 1087 additions and 407 deletions

View File

@ -32,7 +32,7 @@ void do_file(char *filepath);
void set_config(void) {
int32_t ret;
if ((ret = parse_args(args(), argslen(), ARGS)) < 0) {
uprintf("Could not parse args: %d\n", ret);
writefmt("Could not parse args: {d}\n", ret);
}
if (CONFIG.modestr != NULL) {
@ -41,7 +41,7 @@ void set_config(void) {
} else if (string_strcmp(CONFIG.modestr, "runfile") == 0) {
CONFIG.mode = MODE_RUNFILE;
} else {
LOG(LOG_ERR, "Unknown mode %s\n", CONFIG.modestr);
LOG(LOG_ERR, "Unknown mode {s}\n", CONFIG.modestr);
}
} else {
CONFIG.mode = MODE_RUNFILE;
@ -53,7 +53,7 @@ void do_file(char *filepath) {
int32_t ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)filepath, IOCTL_F_READ, 0);
if (ioh < 0) {
LOG(LOG_ERR, "Could not open %s: %s\n", filepath, ERRSTRING(ioh));
LOG(LOG_ERR, "Could not open {s}: {s}\n", filepath, ERRSTRING(ioh));
return;
}
@ -61,27 +61,27 @@ void do_file(char *filepath) {
ioctl(ioh, IOCTL_STAT, (uint64_t)&statbuf, 0, 0);
if (statbuf.type != IOCTLSTAT_FILE) {
LOG(LOG_ERR, "%s is not a file (%d)\n", filepath, statbuf.type);
LOG(LOG_ERR, "{s} is not a file ({d})\n", filepath, statbuf.type);
return;
}
uint8_t *buf = dlmalloc(statbuf.size+1);
string_memset(buf, 0, statbuf.size+1);
if ((ret = ioctl(ioh, IOCTL_READ, (uint64_t)buf, statbuf.size, 0)) < 0) {
LOG(LOG_ERR, "Could not read %s (%d): %s\n", filepath, ioh, ERRSTRING(ioh));
LOG(LOG_ERR, "Could not read {s} ({d}): {s}\n", filepath, ioh, ERRSTRING(ioh));
goto done;
}
InterpResult *res;
bool ok = interp_runstring((const char *)buf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE);
bool ok = interp_runstring((char *)buf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE);
if (!ok) {
uprintf("Interpreter error:\n");
uprintf("%s\n", res->errmsg);
writefmt("Interpreter error:\n");
writefmt("{s}\n", res->errmsg);
goto done;
}
done:
dlfree(buf);
/* dlfree(buf); */
ioctl(ioh, IOCTL_CLOSEF, 0, 0, 0);
}
@ -90,7 +90,7 @@ void do_mode_interactive(void) {
size_t cursor;
for(;;) {
begin:
uprintf("tb# ");
writefmt("tb# ");
cursor = 0;
string_memset(linebuf, 0, LINEBUF_MAX);
@ -102,12 +102,12 @@ void do_mode_interactive(void) {
switch (b) {
case C('C'):
case 0xE9:
uprintf("\n");
writefmt("\n");
goto begin;
break;
case C('L'):
uprintf(ANSIQ_CUR_SET(0, 0));
uprintf(ANSIQ_SCR_CLR_ALL);
writefmt(ANSIQ_CUR_SET(0, 0));
writefmt(ANSIQ_SCR_CLR_ALL);
goto begin;
break;
}
@ -118,7 +118,7 @@ void do_mode_interactive(void) {
if (string_chr_isascii(b) && b != 0 && cursor < LINEBUF_MAX) {
linebuf[cursor++] = b;
uprintf("%c", b);
writefmt("{c}", b);
}
} else {
schedrelease();
@ -128,10 +128,10 @@ void do_mode_interactive(void) {
if (cursor < LINEBUF_MAX) {
linebuf[cursor] = '\0';
}
uprintf("\n");
writefmt("\n");
InterpResult *res;
if (!interp_runstring(linebuf, &res, CONFIG.logcmds, CONFIG.mode == MODE_INTERACTIVE)) {
LOG(LOG_ERR, "%s\n", res->errmsg);
LOG(LOG_ERR, "{s}\n", res->errmsg);
}
}
}
@ -140,17 +140,17 @@ void main(void) {
PID = processctl(-1, PCTL_GETPID, 0, 0, 0);
set_config();
if (CONFIG.preloadpath != NULL) {
LOG(LOG_INF, "Preloading script: %s\n", CONFIG.preloadpath);
LOG(LOG_INF, "Preloading script: {s}\n", CONFIG.preloadpath);
do_file(CONFIG.preloadpath);
}
if (CONFIG.mode == MODE_INTERACTIVE) {
do_mode_interactive();
/* do_mode_interactive(); */
} else if (CONFIG.mode == MODE_RUNFILE) {
if (CONFIG.filepath == NULL) {
uprintf("No file provided\n");
writefmt("No file provided\n");
return;
}
do_file(CONFIG.filepath);