From d7b3b802f414dbf18b5e196ab1a342b19d5f7be8 Mon Sep 17 00:00:00 2001 From: kaashoek Date: Mon, 14 Aug 2006 21:22:13 +0000 Subject: 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 --- sh.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'sh.c') 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(); + } + } + } +} -- cgit v1.2.3