diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/date.c | 19 | ||||
| -rw-r--r-- | userspace/fd.c | 8 | ||||
| -rw-r--r-- | userspace/fsh.c (renamed from userspace/foolshell.c) | 33 | ||||
| -rw-r--r-- | userspace/init.c | 16 | ||||
| -rw-r--r-- | userspace/newcalls.h | 2 | ||||
| -rw-r--r-- | userspace/nonl.c | 15 | ||||
| -rw-r--r-- | userspace/piper.c | 27 | ||||
| -rw-r--r-- | userspace/task1.c | 1 | ||||
| -rw-r--r-- | userspace/test_env.c (renamed from userspace/simple.c) | 0 | ||||
| -rw-r--r-- | userspace/test_math.c (renamed from userspace/test-math.c) | 0 | ||||
| -rw-r--r-- | userspace/test_sysfs.c (renamed from userspace/sysfs_write.c) | 0 |
11 files changed, 55 insertions, 66 deletions
diff --git a/userspace/date.c b/userspace/date.c new file mode 100644 index 0000000..64b8dfc --- /dev/null +++ b/userspace/date.c @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> +#include <time.h> + +int main(int argc, char **argv) +{ + time_t ltime; + time(<ime); + printf("%s", ctime(<ime)); + return 0; +} + + + + + diff --git a/userspace/fd.c b/userspace/fd.c deleted file mode 100644 index 80ffd20..0000000 --- a/userspace/fd.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> -#include <unistd.h> - -int main() -{ -// dup(stdout); - printf("dup\n"); -} diff --git a/userspace/foolshell.c b/userspace/fsh.c index 4d011da..4df4e4e 100644 --- a/userspace/foolshell.c +++ b/userspace/fsh.c @@ -6,6 +6,8 @@ * * A minimalsitic and naive shell developed along the Fool OS kernel. * TODO: Free tokenizer / dynamic size! + * TODO: & with pipes + * TODO: > < */ #include <stdio.h> @@ -14,7 +16,7 @@ #include <string.h> #include <errno.h> #include <string.h> - +#include "interface/fs.h" #include "newcalls.h" @@ -39,7 +41,7 @@ void help() "'cd [dir]' - change directory (set $PWD)\n" "'[binary] [params...]' - run a binary\n" "'[binary] [params...] &' - run a binary in background\n" - " TODO - pipes\n" + " | - pipes\n" "'help' - show this message\n" "'exit' - exit running foolshell\n\n"); @@ -290,8 +292,29 @@ bool setpwd(char *path) bool cd(char *path) { char buf[256]; - if(path==NULL)return setpwd(getenv("HOME")); - if(path[0]=='/')return setpwd(path); - sprintf(buf,"%s/%s",getenv("PWD"),path); + // home + if(path==NULL) + { + sprintf(buf,"%s",getenv("HOME")); + } + // absolute + else if(path[0]=='/') + { + sprintf(buf,"%s",path); + } + // relative + else + { + sprintf(buf,"%s/%s",getenv("PWD"),path); + } + + // check if exists + fs_dirent dirs; + if(-1==_readdir(buf,&dirs,0)) + { + printf("directory not found!\n"); + return false; + } + return setpwd(buf); } diff --git a/userspace/init.c b/userspace/init.c index 8530368..0a3b870 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -3,21 +3,19 @@ int main(int argc, char **argv) { - char *argv1[]={"/bin/foolshell",0}; + char *argv1[]={"/bin/fsh",0}; char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; - time_t ltime; - time(<ime); - printf("fool-init: current time: %s\n", ctime(<ime)); - // loop forever and spawn shells if the top-shell exits while(1) { int pid=_fork(); + if(pid==0) { - _execve("/bin/foolshell",argv1,env1); // replace process with our foolshell :) + printf("fool-init: spawning fool-shell\n"); + _execve("/bin/fsh",argv1,env1); // replace process with our foolshell :) while(1) puts("FATAL ERROR: Something terrible happened. Unable to Execute SHELL!\n"); } @@ -25,9 +23,9 @@ int main(int argc, char **argv) // and respawn SHELL _wait(pid); - printf("fool-init: catched exit of process %d.\n",pid); - printf("fool-init: respawning a new fool-shell\n"); - } + printf("fool-init: respawning new fool-shell\n"); + + } return 0; } diff --git a/userspace/newcalls.h b/userspace/newcalls.h index 4568711..20d8ffd 100644 --- a/userspace/newcalls.h +++ b/userspace/newcalls.h @@ -1,6 +1,6 @@ ////////////////////////////////////////////////// -// this syscall will be moved to newlib later! +// this syscall will be moved to newlib later! TODO! #define SYSCALL_CLONE 83 #define SYSCALL_PIPE 84 #define SYSCALL_DUP2 86 diff --git a/userspace/nonl.c b/userspace/nonl.c deleted file mode 100644 index 3940453..0000000 --- a/userspace/nonl.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -void atex() -{ - printf("atex\n"); -} -int main() -{ - printf("nonextline"); -// fflush(stdout); - -// atexit(&atex); - return EXIT_SUCCESS; -} diff --git a/userspace/piper.c b/userspace/piper.c deleted file mode 100644 index 80cbd27..0000000 --- a/userspace/piper.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> -#include "newcalls.h" - -extern **environ; - -int main() -{ - int fds[2]; - _pipe(fds); - - int pid=_fork(); - - if(pid) - { - _close(fds[1]); - _dup2(fds[0],0); // replace stdin with the read-end of pipe - char *args[]={"grep",NULL}; - _execve("/bin/grep",args,environ); - } - else - { - _close(fds[0]); - _dup2(fds[1],1); // replace stdout with the write-end of our pipe - char *args[]={"cat","hello.txt",0}; - _execve("/bin/cat",args,environ); - } -} diff --git a/userspace/task1.c b/userspace/task1.c index 793b7f8..e220424 100644 --- a/userspace/task1.c +++ b/userspace/task1.c @@ -7,7 +7,6 @@ static ULL fib1_cached_value=0; static ULL fib2_cached_index=1; static ULL fib2_cached_value=1; - ULL fib(ULL i) { if(i==0)return 0; diff --git a/userspace/simple.c b/userspace/test_env.c index 0a04791..0a04791 100644 --- a/userspace/simple.c +++ b/userspace/test_env.c diff --git a/userspace/test-math.c b/userspace/test_math.c index 9327c19..9327c19 100644 --- a/userspace/test-math.c +++ b/userspace/test_math.c diff --git a/userspace/sysfs_write.c b/userspace/test_sysfs.c index 9f91632..9f91632 100644 --- a/userspace/sysfs_write.c +++ b/userspace/test_sysfs.c |
