summaryrefslogtreecommitdiff
path: root/src/luma/luma.cc
blob: 18fcdb75a4db146f097304ac1d07de77b22af482 (plain) (blame)
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
# include <cstdio>
# include <cstdlib>
# include <luma.hh>
# include <fcntl.h>
# include <sys/stat.h>
# include <unistd.h>
[[noreturn]] luma::luma(int const argc,char const * * argv) {
	this->arghandl(argc,argv);
	int file      = ::open("test.luma",O_RDONLY);
	char tok      = '\0';
	char word[0x1000];
	int wordpos = 0x0;
	struct ::stat fst;
	::fstat(file,&fst);
	printf("Size of file is %ld characters.\u000A",fst.st_size);
	::sleep(0x1);
	for(int filepos = 0x0;filepos < fst.st_size;++filepos) {
		if(::read(file,&tok,0x1) < 0x0) {
			std::printf("Error reading file.\u000A");
			::_exit(EXIT_FAILURE);
		}
		if(tok == '\u000A' || tok == '\u0020') {
			if(wordpos == 0x0) continue;
			word[wordpos] = '\0';
			std::printf("The word is \"%s\".\u000A",word);
			word[0x0] = '\0';
			wordpos   = 0x0;
		}
		else {
			word[wordpos] = tok;
			std::printf("Got character '%c' and set word[%d] to it.\u000A",tok,wordpos);
			++wordpos;
		}
	}
	::_exit(EXIT_SUCCESS);
}