init.cmd List devices, Start USB poller, libstring fix str_split_lines (), CE various fixes
This commit is contained in:
6
ce/ce.c
6
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));
|
||||
|
||||
|
||||
19
ce/interp.c
19
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++)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,6 @@ bool interp_is_running (void);
|
||||
|
||||
void interp_shutdown (void);
|
||||
|
||||
extern bool interactive_mode;
|
||||
|
||||
#endif // _INTERP_H
|
||||
|
||||
57
ce/parser.c
57
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++;
|
||||
|
||||
@@ -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
|
||||
|
||||
10
etc/init.cmd
10
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 &
|
||||
|
||||
@@ -64,4 +64,6 @@ void app_main (void) {
|
||||
|
||||
ce_run_init_script ();
|
||||
run_ce_interactive ();
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user