summaryrefslogtreecommitdiffstats
path: root/02_exercise/shell.c
diff options
context:
space:
mode:
authorStefan Zabka <zabkaste@hu-berlin.de>2020-05-21 17:46:10 +0200
committerStefan Zabka <zabkaste@hu-berlin.de>2020-05-21 17:46:10 +0200
commit45b35365a5d0f895caeb6178f5f0a70cfe4464ee (patch)
treebc291ece0cf297f50ba48e8d874a2145721a445f /02_exercise/shell.c
parent0465e79da49900bbd66216d979876654f8977e30 (diff)
parent8da59918c22df70eaec28150867c7e8bfd4bc1ae (diff)
downloadbetriebssysteme-45b35365a5d0f895caeb6178f5f0a70cfe4464ee.tar.gz
betriebssysteme-45b35365a5d0f895caeb6178f5f0a70cfe4464ee.zip
Merge branch 'master' of git.niklashalle.net:uni/sem6/betriebssysteme
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 41378f4..933d162 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') {
@@ -120,6 +125,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);
}