diff options
author | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-05-24 12:52:54 +0200 |
---|---|---|
committer | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-05-24 12:52:54 +0200 |
commit | ea788d16972199ffe97af7faed18e985ded501fc (patch) | |
tree | e8f5e9fc5f75b72167d68ec1523835cfed24758b | |
parent | 0923ca7ccec841b36ce8f3ab22dd9d9fd6fa6b9e (diff) | |
download | betriebssysteme-ea788d16972199ffe97af7faed18e985ded501fc.tar.gz betriebssysteme-ea788d16972199ffe97af7faed18e985ded501fc.zip |
Some reformatting to improve readability
-rw-r--r-- | 02_exercise/process.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/02_exercise/process.c b/02_exercise/process.c index 093b712..94a2977 100644 --- a/02_exercise/process.c +++ b/02_exercise/process.c @@ -1,8 +1,8 @@ -#include <wait.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <wait.h> #include "array.h" #include "process.h" @@ -17,22 +17,19 @@ int parse_command(char const *line, char const *end, Process *p) { } for (size_t i = 0; line + i < end; ++i) { - char c = line[i]; - if (c == ' ' || c == '\0') { + char c; + switch (c = line[i]) { + default: + arrayPush(part) = c; + break; + case ' ': + case '\0': if (arrayLen(part) == 0) continue; arrayPush(part) = '\0'; arrayPush(local_parts) = part; - - if (c == '\0') { - arrayPush(local_parts) = NULL; - break; - } else { - arrayInit(part); - } - } else { - arrayPush(part) = c; + arrayInit(part); } } @@ -77,7 +74,7 @@ int parse_line(char const *const line, Process **processes) { cursor = end + 1; } - size_t p_len = arrayLen(*processes); + size_t p_len = arrayLen(*processes); Process *last = *processes + (p_len - 1); // linking up all processes as we currently only have pipes for multiple commands |