summaryrefslogtreecommitdiff
path: root/sh.c
diff options
context:
space:
mode:
authorkaashoek <kaashoek>2006-08-14 21:22:13 +0000
committerkaashoek <kaashoek>2006-08-14 21:22:13 +0000
commitd7b3b802f414dbf18b5e196ab1a342b19d5f7be8 (patch)
treeccbb34d956ae638d1fbcb24d850b62edb05e841a /sh.c
parentbdb66433031ca96f2fd127995186623cd10c45b3 (diff)
downloadxv6-labs-d7b3b802f414dbf18b5e196ab1a342b19d5f7be8.tar.gz
xv6-labs-d7b3b802f414dbf18b5e196ab1a342b19d5f7be8.tar.bz2
xv6-labs-d7b3b802f414dbf18b5e196ab1a342b19d5f7be8.zip
user-level programs: mkdir and rm
shell parses arguments (very simplistic) readme version of README (sh doesn't deal with capital characters) printf recognizes %c nicer output format for ls
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();
+ }
+ }
+ }
+}