From 5ecb8aafa496e9dfff51378be50eb29858b5465a Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 15 Feb 2023 16:35:40 +0100 Subject: add quote parsing to smash --- smash/main.c | 4 ++-- smash/parser.c | 5 +++-- smash/prompt.c | 22 ++++++++++++++++++++++ smash/prompt.h | 6 ++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 smash/prompt.c create mode 100644 smash/prompt.h (limited to 'smash') diff --git a/smash/main.c b/smash/main.c index efc7bd1..3c5b559 100644 --- a/smash/main.c +++ b/smash/main.c @@ -2,6 +2,7 @@ #include "comment.h" #include "env.h" #include "variable.h" +#include "prompt.h" #include "../lib/sys/io.h" #include "../lib/cstr/cstr.h" @@ -15,7 +16,6 @@ int main(int argc, char *argv[]) { - char prompt[] = "$ "; i64 line_length; int fd = STDIN_FD; char linebuf[BUFSIZ]; @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) while (1) { if (fd == STDIN_FD) - wstd(prompt); + prompt(); line_length = get_next_line_from_fd(fd, linebuf); diff --git a/smash/parser.c b/smash/parser.c index 55a6fd2..a0ea9d8 100644 --- a/smash/parser.c +++ b/smash/parser.c @@ -11,7 +11,7 @@ void __free_argv(char **argv); expression_list_t *new_expression_from_line(char *line) { - u64 n = cstr_split(line, '|'); + u64 n = cstr_split_with_cancel(line, '|', '"'); char *current = line; char *next = 0; expression_list_t *head = 0; @@ -54,7 +54,7 @@ void free_expression(expression_list_t *expression) char **new_argv(char *exp) { - u64 n = cstr_split(exp, ' '); + u64 n = cstr_split_with_cancel(exp, ' ', '"'); char **argv = malloc(sizeof(char*) * (n + 1)); u64 i = 0; char *current = exp; @@ -65,6 +65,7 @@ char **new_argv(char *exp) for (; n > 0; --n) { next = (char*)next_split(current); strip_cstr(current, ' '); + strip_cstr(current, '"'); if (cstr_length(current)) argv[i++] = current; diff --git a/smash/prompt.c b/smash/prompt.c new file mode 100644 index 0000000..3b6b3c2 --- /dev/null +++ b/smash/prompt.c @@ -0,0 +1,22 @@ +#include "prompt.h" + +#include "../lib/sys/execve.h" +#include "../lib/sys/wait4.h" +#include "../lib/sys/fork.h" +#include "../lib/sys/exit.h" +#include "../lib/env/env.h" +#include "../lib/io/io.h" + +void prompt() +{ + int pid = fork(); + + if (pid == 0) { + const char *argv[] = {"/system/config/smash.d/prompt", 0}; + execve(argv[0], argv, getenvp()); + wstd("> "); + exit(0); + } + + wait4(pid, 0, 0, 0); +} diff --git a/smash/prompt.h b/smash/prompt.h new file mode 100644 index 0000000..143a537 --- /dev/null +++ b/smash/prompt.h @@ -0,0 +1,6 @@ +#ifndef PROMPT_H +#define PROMPT_H + +void prompt(); + +#endif -- cgit v1.2.3-70-g09d2