From ea788d16972199ffe97af7faed18e985ded501fc Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Sun, 24 May 2020 12:52:54 +0200 Subject: Some reformatting to improve readability --- 02_exercise/process.c | 23 ++++++++++------------- 1 file 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 #include #include #include #include +#include #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 -- cgit v1.2.3-54-g00ecf