diff options
Diffstat (limited to 'userspace/foolshell.c')
| -rw-r--r-- | userspace/foolshell.c | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 7a029ef..173b0b2 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -27,19 +27,61 @@ int main(int argc, char **argv) { prompt(); fgets(buf,255,input); - buf[strlen(buf)-1]=0; -// puts(buf); + buf[strlen(buf)-1]=0; // remove \n process(buf); + } + + return 0; +} + +char **tokenize(char *buf) +{ + + char **token; + token=malloc(10*sizeof(char*)); + + int l=strlen(buf); + + int i; + int c=0; + + for(i=0;i<l;i++) + { + // init space for next token + token[c]=malloc(256); + + //skip all the whitespace + while(buf[i]==' '&&i<l)i++; + if(i==l)break; + + //get token + int t=0; + + while(buf[i]!=' '&&i<l) + { + token[c][t]=buf[i]; + t++; + i++; + } + token[c][t]=0; + + +// printf("token %i : <%s>\n",c, token[c]); + c++; } + return token; - return 0; } -int process(char *command) +int process(char *buf) { - // copied from trottelshell + + char **token=tokenize(buf); + char *command=token[0]; + // puts(command); + // copied from trottelshell if(!strcmp(command,"HELP")) { @@ -102,7 +144,7 @@ int process(char *command) else if(!strcmp(command,"ECHO")) { - printf("%s\n",command); + printf("%s\n",token[1]); } else |
