diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/less.c | 41 | ||||
| -rw-r--r-- | userspace/xterm/xterm.c | 32 |
2 files changed, 59 insertions, 14 deletions
diff --git a/userspace/less.c b/userspace/less.c new file mode 100644 index 0000000..c1792ae --- /dev/null +++ b/userspace/less.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <stdlib.h> + +#define VERSION "0.1" +int main(int argc, char **argv) +{ + printf("--== fool's %s - version %s ==-\n",argv[0],VERSION); + + // keyboard + int ctrl_fd=_open("/dev/tty"); + + // Input (default stdin) + FILE *in=stdin; + + // Output + FILE *out=stdout; + + // In case a Filename was supplied (TODO: getcwd / setcwd , chdir, open realative to dir. + if(argc>1){ + { + in=fopen(argv[1],"r"); + } + } + + char buf[256]; + + for(int i=0;i<20;i++) + { + if(fgets(buf,256,in)==NULL)return EXIT_SUCCESS; + fputs(buf,out); + } + + while(1) + { + if(fgets(buf,256,in)==NULL)break; + fputs(buf,out); + _read(ctrl_fd,buf,1); // wait for any key + } + + return EXIT_SUCCESS; +} diff --git a/userspace/xterm/xterm.c b/userspace/xterm/xterm.c index 4680ab8..fdee768 100644 --- a/userspace/xterm/xterm.c +++ b/userspace/xterm/xterm.c @@ -1,47 +1,51 @@ +#include <stdlib.h> +#include <stdio.h> + extern char**environ; int main(int argc, char **argv) { _gui_win(); - int xterm_in[2]; - int xterm_out[2]; - - _pipe(xterm_in); - _pipe(xterm_out); vesa_init(); void *tty=terminal_init_vesa(); + //int xterm_in[2]; + int xterm_out[2]; + + //_pipe(xterm_in); + _pipe(xterm_out); + int pid=_fork(); if(!pid) { - _close(xterm_in[1]); + int tty_fd=_open("/dev/tty"); + + //_close(xterm_in[1]); _close(xterm_out[0]); - _dup2(xterm_in[0],0);// stdin + _dup2(tty_fd,0);// stdin _dup2(xterm_out[1],1);// stdout _dup2(xterm_out[1],2);// stderr - _close(xterm_in[0]); - _close(xterm_out[1]); - _execve(argv[1],argv,environ); // replace process with our foolshell or whatever + + while(1); } - _close(xterm_in[0]); + //_close(xterm_in[0]); _close(xterm_out[1]); - _dup2(xterm_in[1],0); // compositor writes here. - _close(xterm_in[1]); + //_dup2(xterm_in[1],0); // compositor writes here. + //_close(xterm_in[1]); while(1) { char buf[1]; _read(xterm_out[0],buf,1); // show what foolshell writes to its stdout/stderr - terminal_put(tty,buf[0]); _gui_rect(); } |
