From 84e493868396fc648faeb25671e10a35178bdaf8 Mon Sep 17 00:00:00 2001 From: Venelin Date: Fri, 10 Mar 2023 19:33:26 +0200 Subject: [PATCH] fix and update readme --- readme.txt | 23 ++++++++++------------- src/parser.cpp | 24 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/readme.txt b/readme.txt index 54d913e..974e78a 100644 --- a/readme.txt +++ b/readme.txt @@ -1,24 +1,24 @@ tft - Terminal Family Tree -tft can create and display family trees on the terminal. +tft is an ncurses program that can create and display family trees on the terminal. HOW TO CREATE: Trees are created using the tft file format, for example this tft file: # This is a comment -Adam, M # Adam is a male +Adam -Eve, F +Eve, F # Eve is female s: Adam # Eve's spouse is Adam -Cain, M +Cain p: Adam, Eve # Cain's parents are Adam and Eve -Abel, M +Abel p: - # Abel's parents are the same as the last person's (Cain) -Seth, M +Seth p: - @@ -43,10 +43,10 @@ DEPENDENCIES: ncursesw development library (libncursesw5-dev on Debian/Ubuntu) HOW TO INSTALL: -Make sure you satisfy the dependencies and have permissons and execute: +Make sure you satisfy the dependencies and execute: git clone https://gitlab.com/venelin98/tft.git cd tft - ./install.sh + sudo ./install.sh HOW TO USE: @@ -60,11 +60,8 @@ HOW TO USE: - - show first names only TFT FORMAT: - - All spaces are ignored e.g.: Adam 0 and Adam0 are equivalent - - '_' in names is converted to ' ' - - Number at the end of a name is used to disambiguate when multiple people have identical names e.g.: - Adam0 is the first added Adam, Adam1 is the second added Adam - - Must end with a newline + - A number after a name is used to disambiguate when multiple people have identical names e.g.: + "Adam 0" is the first added Adam, "Adam 1" is the second added Adam QUESTIONS AND FEEDBACK: venelin98@abv.bg diff --git a/src/parser.cpp b/src/parser.cpp index e020223..a262abd 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -22,6 +22,13 @@ namespace /* internal */ : data(new char[len]) , end(data + len) {} + alloced(const alloced&) = delete; + alloced(alloced&& other) + : data(other.data) + , end(other.end) + { + const_cast(other.data) = nullptr; + } ~alloced() { delete[] data; @@ -42,6 +49,11 @@ namespace /* internal */ struct token { token(const char* b, const char* e); + explicit token(TokenType t) + : type(t) + { + } + U32 size() const { return end - begin; @@ -512,13 +524,13 @@ namespace /* internal */ return res; } - vector tokenize(alloced file) + vector tokenize(const char* data_begin, const char* data_end) { vector tokens; tokens.reserve(256); - char* token_begin = file.data; + const char* token_begin = data_begin; - for(char* it = file.data; it < end_data_; ++it) + for(const char* it = data_begin; it < data_end; ++it) { switch(*it) { @@ -545,8 +557,8 @@ namespace /* internal */ default: break; } } - /* tokens.emplace_back(nullptr, nullptr); */ - /* tokens.back().type = NEW_LINE; */ + tokens.emplace_back(NEW_LINE); + tokens.emplace_back(NEW_LINE); return tokens; } } @@ -561,7 +573,7 @@ Tree parseTftFile(const char* path) MappedFile mapedfile = mapfile(file); alloced preprocessed = removeComments(mapedfile); - vector tokens = tokenize(preprocessed); + vector tokens = tokenize(preprocessed.data, end_data_); state_neutral(tokens);