This commit is contained in:
vrd
2023-02-25 21:52:00 +02:00
parent 222c3e43be
commit 2310343c8a
5 changed files with 46 additions and 12 deletions
+3 -2
View File
@@ -320,12 +320,13 @@ namespace /* internal */
}
Tree parseTftFile(MappedFile file)
Tree parseTftFile(fd_t file)
{
Tree result("name");
cur_tree = &result;
alloced preprocessed = preprocess(file);
MappedFile mapedfile = mapfile(file);
alloced preprocessed = preprocess(mapedfile);
state_neutral(preprocessed.data);
+1 -1
View File
@@ -1,3 +1,3 @@
#include "tree.hpp"
Tree parseTftFile(MappedFile file);
Tree parseTftFile(fd_t);
+22 -3
View File
@@ -3,16 +3,35 @@
#include "tree.hpp"
#include "utils.hpp"
#include "parser.hpp"
#include <string_view>
using std::string_view;
/* using std::cin; */
/* using std::cout; */
using std::cerr;
using namespace std::literals;
int main(int argc, char* argv[])
{
init();
auto f = mapfile("example_tree.tft");
parseTftFile(f).display();
if(argc < 2)
{
cerr << "Usage: tft FILES...\nTry 'tft --help' for more information";
return 1;
}
for(int i = 1; i < argc; ++i)
{
if(string_view(argv[i]) == "--help"sv) /* sv worth it? */
{
/* todo */
return 0; /* todo exit curses */
}
fd_t file = openOrDie(argv[i]);
parseTftFile(file).display();
}
Tree test1("Dechkovi");
/* test1.loadFromFile(); */
+14 -3
View File
@@ -4,6 +4,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <iostream>
void init()
{
@@ -25,10 +26,8 @@ void init()
wnoutrefresh(stdscr); /* if not present the first real refresh is missed */
}
MappedFile mapfile(const char* path)
MappedFile mapfile(fd_t file)
{
int file = open(path, O_RDONLY);
MappedFile res;
res.len = lseek(file, 0, SEEK_END);
res.data = (char*)mmap(nullptr, res.len, PROT_READ, MAP_PRIVATE, file, 0);
@@ -37,6 +36,18 @@ MappedFile mapfile(const char* path)
return res;
}
fd_t openOrDie(const char* path)
{
fd_t file = open(path, O_RDONLY);
if(file == -1)
{
std::cerr << "Can't open: " << path << '\n';
exit(1);
}
return file;
}
bool willBeVisible(I16 drawY, I16 drawX, U16 height, U16 width)
{
return (drawY + height > 0) && (drawX + width > 0) &&
+6 -3
View File
@@ -23,15 +23,18 @@
/* return lhs; */
/* } */
void init();
using fd_t = int; /* file descriptor */
struct MappedFile
{
char* data;
unsigned len;
};
MappedFile mapfile(const char* path);
void init();
MappedFile mapfile(fd_t);
fd_t openOrDie(const char* path);
template <class Vec>
void remove(Vec& vec, size_t pos) /* Remove from vector by moving the last element in its place */