diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/cat.c | 16 | ||||
| -rw-r--r-- | userspace/clear.c | 3 | ||||
| -rw-r--r-- | userspace/crt0.s | 1 | ||||
| -rw-r--r-- | userspace/foolshell.c | 2 | ||||
| -rw-r--r-- | userspace/init.c | 8 | ||||
| -rw-r--r-- | userspace/ls.c | 22 | ||||
| -rw-r--r-- | userspace/snake2.h | 2 |
7 files changed, 24 insertions, 30 deletions
diff --git a/userspace/cat.c b/userspace/cat.c index 800a14b..39d994f 100644 --- a/userspace/cat.c +++ b/userspace/cat.c @@ -1,18 +1,24 @@ #include <stdio.h> -int main() +int main(int argc, char **argv) { + FILE *f; + if(argc>1)f=fopen(argv[1],"r"); + else f=stdin; + + setvbuf(stdin,NULL,_IONBF,0); + setvbuf(stdout,NULL,_IONBF,0); char c; - printf("-- read from stderr byte by byte --\n"); + printf("-- read from file byte by byte --\n"); - while(_poll(2)){ - fread(&c,1,1,stderr); + while(fread(&c,1,1,f)) + { printf("%c",c); } - printf("\n-- no more data on stderr --\n"); + printf("\n-- no more data on this file --\n"); return 0; } diff --git a/userspace/clear.c b/userspace/clear.c index 38efeb6..9557760 100644 --- a/userspace/clear.c +++ b/userspace/clear.c @@ -1,6 +1,7 @@ +#include <stdio.h> int main() { printf("\033c"); - fflush(0); // force printing to console + fflush(stdout); // force printing to console return 0; } diff --git a/userspace/crt0.s b/userspace/crt0.s index ad9884f..9ef2a67 100644 --- a/userspace/crt0.s +++ b/userspace/crt0.s @@ -26,7 +26,6 @@ movl $0xf5000000, _impure_ptr pop %eax mov %eax, environ - # call main (argc and argv are on the stack) call main diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 3c1fb50..6877adb 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -257,7 +257,7 @@ int process(char *buf) exit(0); } - if(token[1]!=NULL&&strcmp(token[1],"branch"))_wait(pid); + if(token[1]==NULL||strcmp(token[1],"branch"))_wait(pid); } return 0; diff --git a/userspace/init.c b/userspace/init.c index a367fd9..3384edb 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,13 +1,10 @@ #include <stdio.h> #include <time.h> - int main(int argc, char **argv) { - char *argv1[]={"/bin/foolshell",0}; char *env1[]={"PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; - printf("fool-init\n"); time_t ltime; time(<ime); @@ -18,8 +15,6 @@ int main(int argc, char **argv) { int pid=_fork(); - printf("fool-init: forked pid=%d\n", pid); - if(pid==0) { _execve("/bin/foolshell",argv1,env1); // replace process with our foolshell :) @@ -31,8 +26,7 @@ int main(int argc, char **argv) _wait(pid); printf("fool-init: catched exit of process %d.\n",pid); - printf("fool-init: respawning a Fools Shell\n"); - + printf("fool-init: respawning a new fool-shell\n"); } return 0; diff --git a/userspace/ls.c b/userspace/ls.c index 413755b..416e139 100644 --- a/userspace/ls.c +++ b/userspace/ls.c @@ -1,4 +1,4 @@ -#include "fs/fs.h" +#include "interface/fs.h" void usage() { @@ -7,10 +7,7 @@ void usage() int main(int argc, char **argv) { - - fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); char *dir=getenv("PWD"); -// printf("PWD = %s\n",dir); if(argc==2) { @@ -26,19 +23,16 @@ int main(int argc, char **argv) } } - int ls=_readdir(dir,dirs,25); - if(ls==-1) + fs_dirent dirs; + uint32_t pos=0; + int cnt=0; + while(1) { - printf("%s: file or directory '%s' not found.\n",argv[0],dir); - return 0; + cnt =_readdir(dir,&dirs,&pos); + if(cnt<1) break; + printf("% 12i %s%c\n",dirs.inode, dirs.name, ((dirs.type==FS_FILE_TYPE_DIR)?'/':' ')); } - int i; - for(i=0;i<ls;i++) - { - printf("%i %s%c\n",dirs[i].inode, dirs[i].name, ((dirs[i].type==FS_FILE_TYPE_DIR)?'/':' ')); - } - return 0; } diff --git a/userspace/snake2.h b/userspace/snake2.h index 06ca797..d4c47a8 100644 --- a/userspace/snake2.h +++ b/userspace/snake2.h @@ -1,6 +1,6 @@ ////////////////////////////////////////////////// -// this syscall will be move to newlib later! +// this syscall will be moved to newlib later! #define SYSCALL_CLONE 83 int _clone(void) |
