init.cmd List devices, Start USB poller, libstring fix str_split_lines (), CE various fixes
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 35s
Build documentation / build-and-deploy (push) Successful in 29s

This commit is contained in:
2026-04-07 18:12:17 +02:00
parent bef3b79502
commit 2f186921d6
10 changed files with 112 additions and 19 deletions

View File

@@ -72,6 +72,8 @@ static bool split_lines_cb (void* ctx, const char* start, size_t len) {
if (line[0] != '\0')
exec_line (line);
free (line);
return true;
}
@@ -85,6 +87,8 @@ void app_main (void) {
int has_script = env_get (process_get_pgid (), "s", (void*)scriptpathbuf, sizeof (scriptpathbuf));
if (has_script == ST_OK) {
interactive_mode = false;
char volume[VOLUME_MAX];
const char* path;
int ret;
@@ -114,6 +118,8 @@ void app_main (void) {
free (buffer);
} else {
interactive_mode = true;
while (interp_is_running ()) {
memset (line, 0, sizeof (line));

View File

@@ -27,6 +27,8 @@
static bool run = true;
bool interactive_mode;
bool interp_is_running (void) { return run; }
void interp_shutdown (void) { run = false; }
@@ -45,8 +47,12 @@ static void human_size (double size, double* out, char** str) {
}
static void echo (struct context* context, char** strings, size_t strings_count) {
for (size_t i = 0; i < strings_count; i++)
cprintf (context, "%s ", strings[i]);
for (size_t i = 0; i < strings_count; i++) {
cprintf (context, "%s", strings[i]);
if (i != strings_count - 1)
cprintf (context, " ");
}
}
static void mkfile (struct context* context, char** file_paths, size_t files_count) {
@@ -451,6 +457,7 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context, bool run_
cprintf (context, "started background process: PID %d\n", pid);
} else {
if (interactive_mode) {
struct cmd_write_proc_ctx wpctx = {.pgid = pgid, .cancel_pid = pid};
struct process_data* write_pdata = process_spawn (&cmd_write_proc, (void*)&wpctx);
@@ -464,6 +471,16 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context, bool run_
process_data_free (write_pdata);
kill (collect_pdata->pid);
process_data_free (collect_pdata);
} else {
struct process_data* collect_pdata =
process_spawn (&cmd_collect_proc, (void*)(uintptr_t)pgid);
exec_partial_fini (pid);
wait_for_pid (pid);
kill (collect_pdata->pid);
process_data_free (collect_pdata);
}
}
}
}

View File

@@ -11,4 +11,6 @@ bool interp_is_running (void);
void interp_shutdown (void);
extern bool interactive_mode;
#endif // _INTERP_H

View File

@@ -125,6 +125,31 @@ struct ast_node* run_bg_led (struct parser* parser, struct token* token, struct
return node;
}
static char handle_escape (char c) {
switch (c) {
case 'n':
return '\n';
case 't':
return '\t';
case 'r':
return '\r';
case 'b':
return '\b';
case 'f':
return '\f';
case 'v':
return '\v';
case '\\':
return '\\';
case '"':
return '\"';
case '\'':
return '\'';
default:
return c;
}
}
void tokenize (struct list_node_link** tokens, const char* text) {
const char* p = text;
@@ -134,6 +159,36 @@ void tokenize (struct list_node_link** tokens, const char* text) {
continue;
}
if (*p == '"') {
p++;
struct token* token = arena_malloc (&arena, sizeof (*token));
memset (token, 0, sizeof (*token));
size_t i = 0;
while (*p && *p != '"') {
if (i >= TOKEN_MAX - 1)
break;
if (*p == '\\') {
p++;
if (*p) {
token->buffer[i++] = handle_escape (*p);
p++;
}
} else {
token->buffer[i++] = *p;
p++;
}
}
if (*p == '"')
p++;
token->class = TOKEN_CLASS_WORD;
list_append (*tokens, &token->tokens_link);
continue;
}
if (*p == '(' || *p == ')' || *p == ';' || *p == '>' || *p == '&') {
struct token* token = arena_malloc (&arena, sizeof (*token));
memset (token, 0, sizeof (*token));
@@ -160,7 +215,7 @@ void tokenize (struct list_node_link** tokens, const char* text) {
memset (token, 0, sizeof (*token));
size_t i = 0;
while (*p && !isspace (*p) && *p != '(' && *p != ')' && *p != ';' && *p != '>') {
while (*p && !isspace (*p) && *p != '(' && *p != ')' && *p != ';' && *p != '>' && *p != '"') {
if (i < TOKEN_MAX - 1)
token->buffer[i++] = *p;
p++;

View File

@@ -3,8 +3,8 @@
#include <list.h>
#define TOKEN_MAX 128
#define CMD_ARGS_MAX 128
#define TOKEN_MAX 512
#define CMD_ARGS_MAX 512
#define TOKEN_CLASS_OPAREN 0
#define TOKEN_CLASS_CPAREN 1

View File

@@ -1 +1,9 @@
echo HELLO!
echo "Terminal information: "
terminfo
echo "Available devices:\n"
sys:/devices -C list_all
echo "Starting USB poller...\n"
sys:/usb -C poll &

View File

@@ -64,4 +64,6 @@ void app_main (void) {
ce_run_init_script ();
run_ce_interactive ();
for (;;)
;
}

View File

@@ -4,7 +4,7 @@
#include <libk/hash.h>
#include <libk/std.h>
#define PROC_ENV_VAR_MAX 128
#define PROC_ENV_VAR_MAX 512
struct procgroup;

View File

@@ -85,8 +85,9 @@ void str_split_lines (const char* str, size_t total_len, void* ctx, strtokenize_
if (!cb (ctx, start, line_len))
return;
start = end + 1;
remaining = total_len - (size_t)(start - str);
size_t consumed = line_len + 1;
start += consumed;
remaining -= consumed;
if (remaining == 0)
cb (ctx, start, 0);

View File

@@ -41,6 +41,8 @@ void app_main (void) {
sched ();
}
}
free (infos);
} else {
mprintf ("ERROR unknown command %s\n", commandbuf);
}