summaryrefslogtreecommitdiff
path: root/userspace/less.c
blob: c1792ae1dca12d4b04977eaf6fe1ac93c9fe2f8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
}