diff options
Diffstat (limited to 'userspace/less.c')
| -rw-r--r-- | userspace/less.c | 41 |
1 files changed, 41 insertions, 0 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; +} |
