summaryrefslogtreecommitdiffstats
path: root/02_exercise/shell.c
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-05-21 14:11:38 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-05-21 14:11:38 +0200
commit8da59918c22df70eaec28150867c7e8bfd4bc1ae (patch)
tree755641437d6a3edc4383ff185b92424429a6097d /02_exercise/shell.c
parent47f29d306e120f8233e87d43bccd8c97ccf88831 (diff)
downloadbetriebssysteme-8da59918c22df70eaec28150867c7e8bfd4bc1ae.tar.gz
betriebssysteme-8da59918c22df70eaec28150867c7e8bfd4bc1ae.zip
sdfghj
Diffstat (limited to '02_exercise/shell.c')
-rw-r--r--02_exercise/shell.c14
1 files changed, 10 insertions, 4 deletions
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 <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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);
}