diff options
Diffstat (limited to '02_exercise/process.c')
-rw-r--r-- | 02_exercise/process.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/02_exercise/process.c b/02_exercise/process.c index 8f6589d..fb55236 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" @@ -11,29 +11,33 @@ int parse_command(char const *line, char const *end, process *p) { char *part; char **local_parts; - if (arrayInit(part) != 0 || arrayInit(local_parts) != 0) { fprintf(stderr, "Failed to prepare new part / parts array whilst parsing line"); return -1; } for (size_t i = 0; line + i < end; ++i) { - char c = line[i]; - if (c == '\t' || c == ' ' || c == '\0') { + char c; + switch (c = line[i]) { + default: + arrayPush(part) = c; + break; + case ' ': + case '\t': + case '\0': if (arrayLen(part) == 0) continue; arrayPush(part) = '\0'; arrayPush(local_parts) = part; arrayInit(part); - } else { - arrayPush(part) = c; } } if (arrayLen(part) == 0) { arrayRelease(part); } else { + arrayPush(part) = '\0'; arrayPush(local_parts) = part; } |