diff --git a/ce/ce.c b/ce/ce.c index c6b74eb..77c4a6e 100644 --- a/ce/ce.c +++ b/ce/ce.c @@ -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)); diff --git a/ce/interp.c b/ce/interp.c index b3b01d3..cc22afd 100644 --- a/ce/interp.c +++ b/ce/interp.c @@ -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,19 +457,30 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context, bool run_ cprintf (context, "started background process: PID %d\n", pid); } else { - struct cmd_write_proc_ctx wpctx = {.pgid = pgid, .cancel_pid = pid}; + 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); - struct process_data* collect_pdata = - process_spawn (&cmd_collect_proc, (void*)(uintptr_t)pgid); + struct process_data* write_pdata = process_spawn (&cmd_write_proc, (void*)&wpctx); + struct process_data* collect_pdata = + process_spawn (&cmd_collect_proc, (void*)(uintptr_t)pgid); - exec_partial_fini (pid); - wait_for_pid (pid); + exec_partial_fini (pid); + wait_for_pid (pid); - kill (write_pdata->pid); - process_data_free (write_pdata); - kill (collect_pdata->pid); - process_data_free (collect_pdata); + kill (write_pdata->pid); + 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); + } } } } diff --git a/ce/interp.h b/ce/interp.h index d00829b..7159ba9 100644 --- a/ce/interp.h +++ b/ce/interp.h @@ -11,4 +11,6 @@ bool interp_is_running (void); void interp_shutdown (void); +extern bool interactive_mode; + #endif // _INTERP_H diff --git a/ce/parser.c b/ce/parser.c index 6dc1c45..2c4509f 100644 --- a/ce/parser.c +++ b/ce/parser.c @@ -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++; diff --git a/ce/parser.h b/ce/parser.h index 15e0826..f575549 100644 --- a/ce/parser.h +++ b/ce/parser.h @@ -3,8 +3,8 @@ #include -#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 diff --git a/etc/init.cmd b/etc/init.cmd index 46f6723..754f9b5 100644 --- a/etc/init.cmd +++ b/etc/init.cmd @@ -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 & diff --git a/init/init.c b/init/init.c index 2278a66..1dcf013 100644 --- a/init/init.c +++ b/init/init.c @@ -64,4 +64,6 @@ void app_main (void) { ce_run_init_script (); run_ce_interactive (); + for (;;) + ; } diff --git a/kernel/proc/env.h b/kernel/proc/env.h index a73f57f..f43c36f 100644 --- a/kernel/proc/env.h +++ b/kernel/proc/env.h @@ -4,7 +4,7 @@ #include #include -#define PROC_ENV_VAR_MAX 128 +#define PROC_ENV_VAR_MAX 512 struct procgroup; diff --git a/libstring/string.c b/libstring/string.c index 01d5e8d..5b8377d 100644 --- a/libstring/string.c +++ b/libstring/string.c @@ -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); diff --git a/usb/usb.c b/usb/usb.c index ce9a1ab..499cefb 100644 --- a/usb/usb.c +++ b/usb/usb.c @@ -41,6 +41,8 @@ void app_main (void) { sched (); } } + + free (infos); } else { mprintf ("ERROR unknown command %s\n", commandbuf); }