summaryrefslogtreecommitdiff
path: root/sh.c
diff options
context:
space:
mode:
Diffstat (limited to 'sh.c')
-rw-r--r--sh.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/sh.c b/sh.c
index 9d4a308..e2b8959 100644
--- a/sh.c
+++ b/sh.c
@@ -1,9 +1,11 @@
-#include "user.h"
#include "types.h"
+#include "stat.h"
+#include "user.h"
#include "fs.h"
#include "fcntl.h"
char *args[100];
+void parse(char buf[]);
int
main(void)
@@ -18,8 +20,7 @@ main(void)
continue;
pid = fork();
if(pid == 0){
- args[0] = buf;
- args[1] = 0;
+ parse(buf);
exec(buf, args);
printf(1, "%s: not found\n", buf);
exit();
@@ -28,3 +29,21 @@ main(void)
wait();
}
}
+
+void
+parse(char buf[])
+{
+ int j = 1;
+ int i;
+ args[0] = buf;
+ for (i = 0; buf[i] != '\0'; i++) {
+ if (buf[i] == ' ') {
+ buf[i] = '\0';
+ args[j++] = buf + i+1;
+ if (j >= 100) {
+ printf(2, "too many args\n");
+ exit();
+ }
+ }
+ }
+}