diff options
Diffstat (limited to '03_exercise/srv/process.c')
-rw-r--r-- | 03_exercise/srv/process.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/03_exercise/srv/process.c b/03_exercise/srv/process.c index c5be8c3..fe66a66 100644 --- a/03_exercise/srv/process.c +++ b/03_exercise/srv/process.c @@ -20,25 +20,25 @@ int parse_command(char const *line, char const *end, process *p) { for (size_t i = 0; line + i < end; ++i) { 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); + default: + arrayPush(part) = c; + break; + case ' ': + case '\t': + case '\0': + if (arrayLen(part) == 0) + continue; + + arrayPush(part) = '\0'; + arrayPush(local_parts) = part; + arrayInit(part); } } if (arrayLen(part) == 0) { arrayRelease(part); } else { - arrayPush(part) = '\0'; + arrayPush(part) = '\0'; arrayPush(local_parts) = part; } @@ -51,22 +51,22 @@ int parse_command(char const *line, char const *end, process *p) { int parse_line(char const *const line, process **processes) { // splits the line at | and then parses the commands - int ret_code; + int ret_code; if (arrayInit(*processes) != 0) { perror("Failed to initialize processes array"); return -1; } - bool done = false; + bool done = false; char const *cursor = line; while (!done) { - process p = {.argv = NULL, .argc = 0, .in_fd = 0, .out_fd = 0, .pid = 0, .blocking = true}; - char const *end = strchr(cursor, '|'); + process p = {.argv = NULL, .argc = 0, .in_fd = 0, .out_fd = 0, .pid = 0, .blocking = true}; + char const *end = strchr(cursor, '|'); if (end == NULL) { done = true; - end = line + strlen(line); + end = line + strlen(line); } if ((ret_code = parse_command(cursor, end, &p)) != 0) { @@ -87,7 +87,7 @@ int parse_line(char const *const line, process **processes) { perror("Failed to create pipe"); return -1; } - (*processes)[i].out_fd = fds[1]; + (*processes)[i].out_fd = fds[1]; (*processes)[i + 1].in_fd = fds[0]; } @@ -113,7 +113,7 @@ int exec_command(process p) { dup2(p.in_fd, 0); close(p.in_fd); } - if(p.in_fd == 0 && !p.blocking) { + if (p.in_fd == 0 && !p.blocking) { close(0); } @@ -156,7 +156,7 @@ void free_processes(process **pr) { while (!arrayIsEmpty(processes)) { process p = arrayPop(processes); while (!arrayIsEmpty(p.argv)) { - char *tmp = arrayTop(p.argv); + char *tmp = arrayTop(p.argv); if (tmp) { arrayRelease(tmp); } |