diff options
author | kaashoek <kaashoek> | 2006-08-14 21:22:13 +0000 |
---|---|---|
committer | kaashoek <kaashoek> | 2006-08-14 21:22:13 +0000 |
commit | d7b3b802f414dbf18b5e196ab1a342b19d5f7be8 (patch) | |
tree | ccbb34d956ae638d1fbcb24d850b62edb05e841a /sh.c | |
parent | bdb66433031ca96f2fd127995186623cd10c45b3 (diff) | |
download | xv6-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.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -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(); + } + } + } +} |