From 65a859ac5b721c8d3e0123351ad99690e2e7a876 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Fri, 21 Nov 2014 15:37:45 +0100 Subject: preparing switch to ELF userspace --- userspace/shell.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 userspace/shell.c (limited to 'userspace/shell.c') diff --git a/userspace/shell.c b/userspace/shell.c new file mode 100644 index 0000000..36912c8 --- /dev/null +++ b/userspace/shell.c @@ -0,0 +1,147 @@ +#include +#include +#include +#include "syscalls.c" +#include "../fs/fs.h" + +void hello() { + puts( + "Welcome to FoolShell v0.1" + ); +} + +void prompt() { + printf( + "$ " + ); +} + +int main(int argc, char **argv) +{ + hello(); + + FILE *input; + input=fopen("input.txt","r"); + char *buf=malloc(256); + + while(1) + { + prompt(); + fgets(buf,255,input); + 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\n",c, token[c]); + c++; + + } + + return token; + +} + +int process(char *buf) +{ + + char **token=tokenize(buf); + char *command=token[0]; + // puts(command); + // copied from trottelshell + + if(!strcmp(command,"help")) + { + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'"); + } + else if(!strcmp(command,"ls")) + { + fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); + + int ls=readdir(atoi(token[1]),dirs,25); + + int i; + for(i=0;i