From 8da59918c22df70eaec28150867c7e8bfd4bc1ae Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Thu, 21 May 2020 14:11:38 +0200 Subject: sdfghj --- 02_exercise/shell.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to '02_exercise/shell.c') diff --git a/02_exercise/shell.c b/02_exercise/shell.c index ed53897..1bdeab6 100644 --- a/02_exercise/shell.c +++ b/02_exercise/shell.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -31,6 +32,10 @@ int main(void) { exit(-1); } + if (strspn(line, " \n\t") == strlen(line)) { + continue; + } + line[length - 1] = '\0'; // cut the line feed char **arguments = NULL; @@ -82,11 +87,11 @@ int parse_line(char const *line, char ***parts, size_t *part_count) { return -1; } - char c; - int i = 0; - while (true) { - c = line[i++]; + for (size_t i = 0; i < strlen(line) + 1; ++i) { + char c = line[i]; if (c == ' ' || c == '\0') { + if (arrayLen(part) == 0) + continue; arrayPush(part) = '\0'; arrayPush(local_parts) = part; if (c == '\0') { @@ -131,6 +136,7 @@ int exec_command(const char *path, char *const argv[], unsigned timeout) { close(pipefd[1]); execvp(path, argv); fprintf(stderr, "could not execute \"%s\"\n", path); + fflush(stderr); exit(-1); } -- cgit v1.2.3-54-g00ecf