From 16894e29832cf9b7b3884ccc0150cb7de3a083da Mon Sep 17 00:00:00 2001 From: Venelin Date: Sat, 18 Feb 2023 19:02:20 +0200 Subject: [PATCH] tft create user tree --- .gitignore | 1 + create_tree.sh | 30 +++++++++++++++++++++++++++++ create_tree.hpp => example_tree.hpp | 0 build.sh => install.sh | 8 ++++++-- {common => src/common}/basicTypes.h | 0 famt.cpp => src/famt.cpp | 12 ++++++------ person.cpp => src/person.cpp | 0 person.hpp => src/person.hpp | 0 tree.cpp => src/tree.cpp | 4 ++-- tree.hpp => src/tree.hpp | 0 utils.cpp => src/utils.cpp | 0 utils.hpp => src/utils.hpp | 0 todo.txt | 2 +- 13 files changed, 46 insertions(+), 11 deletions(-) create mode 100755 create_tree.sh rename create_tree.hpp => example_tree.hpp (100%) rename build.sh => install.sh (71%) rename {common => src/common}/basicTypes.h (100%) rename famt.cpp => src/famt.cpp (98%) rename person.cpp => src/person.cpp (100%) rename person.hpp => src/person.hpp (100%) rename tree.cpp => src/tree.cpp (99%) rename tree.hpp => src/tree.hpp (100%) rename utils.cpp => src/utils.cpp (100%) rename utils.hpp => src/utils.hpp (100%) diff --git a/.gitignore b/.gitignore index 7e88db6..75403b6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ GPATH GRTAGS GTAGS +*.tft diff --git a/create_tree.sh b/create_tree.sh new file mode 100755 index 0000000..0090d62 --- /dev/null +++ b/create_tree.sh @@ -0,0 +1,30 @@ +#!/bin/sh +set -e + +if [ "$1" = '' ] +then + echo 'The first argument needs to be the tree file' + exit 1 +fi + +tree_file="$(realpath "$1")" +start_dir="$PWD" +script_dir="$(dirname $(readlink -f $0))" + +cd "$script_dir/src" + +language=' + -std=c++17 + -fno-rtti + -fno-exceptions + -fno-non-call-exceptions + -fno-common' +# force each global variable to be only defined once + +warnings='-Wall -Wextra -Wpedantic' #-fanalyzer + +cp -f "$tree_file" user_tree.hpp +g++ -o "$start_dir/${1%.*}.tft" $language $warnings -march=native -DNDEBUG -pipe -g *.cpp -lncursesw +rm user_tree.hpp +cd "$start_dir" +exec "./${1%.*}.tft" diff --git a/create_tree.hpp b/example_tree.hpp similarity index 100% rename from create_tree.hpp rename to example_tree.hpp diff --git a/build.sh b/install.sh similarity index 71% rename from build.sh rename to install.sh index 2004640..84f8574 100755 --- a/build.sh +++ b/install.sh @@ -1,6 +1,8 @@ #!/bin/sh +set -e -mkdir -p bin/release +cd src +# mkdir -p bin/release language=' -std=c++17 @@ -29,5 +31,7 @@ warnings=' other='-fno-fat-lto-objects' -g++ -o bin/release/famt $language $optimizations $warnings $other -DNDEBUG -pipe -s *.cpp -lncursesw +g++ -o tft $language $optimizations $warnings $other -DNDEBUG -pipe -s *.cpp -lncursesw +chmod 775 tft +exec mv tft /usr/local/bin #-static -lncursesw -ltinfo diff --git a/common/basicTypes.h b/src/common/basicTypes.h similarity index 100% rename from common/basicTypes.h rename to src/common/basicTypes.h diff --git a/famt.cpp b/src/famt.cpp similarity index 98% rename from famt.cpp rename to src/famt.cpp index ffd49d3..27ba931 100644 --- a/famt.cpp +++ b/src/famt.cpp @@ -3,16 +3,16 @@ #include "tree.hpp" #include "utils.hpp" -#include "create_tree.hpp" +#include "user_tree.hpp" -using std::cin; -using std::cout; +/* using std::cin; */ +/* using std::cout; */ int main() { setlocale(LC_ALL, "en_US.UTF-8"); /* Init ncurses */ - initscr(); /* Start curses mode */ + initscr(); /* Start curses mode */ curs_set(0); /* Hide cursor */ noecho(); cbreak(); /* get input instantly */ @@ -29,15 +29,15 @@ int main() Tree test1("Dechkovi"); test1.loadFromFile(); - Tree test2("Karamanovi"); /* test1.addPerson("Rumen", true, Nobody, Nobody, {1968, 8, 9}); */ /* test1.addPerson("Nadejda", false, Nobody, Nobody, {1972, 12, 15}); */ /* test1.addRelation(0, Spouse, 1); */ /* test1.addPerson("Venelin", true, 0, 1, {1998, 6, 9}); */ /* test1.addPerson("Vasil", true, 0, 1, {2001, 1, 16}); */ - test1.saveToFile(); + /* test1.saveToFile(); */ + Tree test2("Karamanovi"); test2.addPerson("Vasil Dimitrov", true, Nobody, Nobody, {1941, 5, 18}); test2.addPerson("Maria", false); test2.addRelation(0, Spouse, 1); diff --git a/person.cpp b/src/person.cpp similarity index 100% rename from person.cpp rename to src/person.cpp diff --git a/person.hpp b/src/person.hpp similarity index 100% rename from person.hpp rename to src/person.hpp diff --git a/tree.cpp b/src/tree.cpp similarity index 99% rename from tree.cpp rename to src/tree.cpp index 5bac128..1012dcd 100644 --- a/tree.cpp +++ b/src/tree.cpp @@ -206,7 +206,7 @@ RelType Tree::findRelation(person_id first, person_id second) const void Tree::saveToFile() const { - ofstream file(treeName + ".famt", std::ios::binary); + ofstream file(treeName + ".tft", std::ios::binary); file.write((const char*)(&numPeople), sizeof(numPeople)); for (const Person& p: people) @@ -222,7 +222,7 @@ void Tree::saveToFile() const bool Tree::loadFromFile() { - ifstream file(treeName + ".famt", std::ios::binary); + ifstream file(treeName + ".tft", std::ios::binary); file.read((char*)(&numPeople), sizeof(numPeople)); diff --git a/tree.hpp b/src/tree.hpp similarity index 100% rename from tree.hpp rename to src/tree.hpp diff --git a/utils.cpp b/src/utils.cpp similarity index 100% rename from utils.cpp rename to src/utils.cpp diff --git a/utils.hpp b/src/utils.hpp similarity index 100% rename from utils.hpp rename to src/utils.hpp diff --git a/todo.txt b/todo.txt index ba93c62..a94fcba 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,6 @@ Help -ffindRelative +findRelative findRelation - extend