diff --git a/install.sh b/install.sh index 84f8574..9068c29 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,9 @@ #!/bin/sh set -e +# cp tft_create /usr/local/bin + cd src -# mkdir -p bin/release language=' -std=c++17 @@ -31,7 +32,7 @@ warnings=' other='-fno-fat-lto-objects' -g++ -o tft $language $optimizations $warnings $other -DNDEBUG -pipe -s *.cpp -lncursesw +g++ -o tft $language $optimizations $warnings $other -DNDEBUG -pipe -s tft.cpp tree.cpp person.cpp utils.cpp -lncursesw chmod 775 tft exec mv tft /usr/local/bin #-static -lncursesw -ltinfo diff --git a/src/create_tree.cpp b/src/create_tree.cpp new file mode 100644 index 0000000..6da506a --- /dev/null +++ b/src/create_tree.cpp @@ -0,0 +1,15 @@ +#include +#include "tree.hpp" +#include "utils.hpp" + +#include "user_tree.hpp" + +int main() +{ + init(); + + create_tree(); + + endwin(); /* stop ncursers */ + return 0; +} diff --git a/src/famt.cpp b/src/tft.cpp similarity index 93% rename from src/famt.cpp rename to src/tft.cpp index 27ba931..b5f602a 100644 --- a/src/famt.cpp +++ b/src/tft.cpp @@ -3,28 +3,12 @@ #include "tree.hpp" #include "utils.hpp" -#include "user_tree.hpp" /* using std::cin; */ /* using std::cout; */ -int main() +int main(int argc, char* argv[]) { - setlocale(LC_ALL, "en_US.UTF-8"); - - /* Init ncurses */ - initscr(); /* Start curses mode */ - curs_set(0); /* Hide cursor */ - noecho(); - cbreak(); /* get input instantly */ - keypad(stdscr, true); - start_color(); - use_default_colors(); - /* init_pair(5, COLOR_BLACK, COLOR_BLACK); */ - /* bkgd(COLOR_PAIR(5)); */ - init_pair(COLOR_MALE, COLOR_CYAN, -1); /* -1 means use default */ - init_pair(COLOR_FEMALE, COLOR_RED, -1); - init_pair(COLOR_SELECTED, COLOR_YELLOW, -1); - wnoutrefresh(stdscr); /* if not present the first real refresh is missed */ + init(); Tree test1("Dechkovi"); test1.loadFromFile(); @@ -53,10 +37,6 @@ int main() (test2 + test1).display(); - create_tree(); - - - /* Tree firstTree("firstTree"); */ /* firstTree.addPerson("Адам", true, Nobody, Nobody, {0, 1, 6}); */ /* firstTree.addPerson("Ева", false, Nobody, Nobody, {0, 1, 6}); */ diff --git a/src/tree.cpp b/src/tree.cpp index 1012dcd..84bc4a9 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -7,6 +7,7 @@ using std::ofstream; using std::ifstream; using std::vector; +using std::string; Tree Tree::operator+ (const Tree& other) const { @@ -206,7 +207,13 @@ RelType Tree::findRelation(person_id first, person_id second) const void Tree::saveToFile() const { - ofstream file(treeName + ".tft", std::ios::binary); + const char* HOME = getenv("HOME"); + string tftDir(HOME); + tftDir += "/.tft"; + + system(("mkdir " + tftDir).c_str()); + + ofstream file(tftDir + '/' + treeName + ".tftb", std::ios::binary); file.write((const char*)(&numPeople), sizeof(numPeople)); for (const Person& p: people) @@ -222,7 +229,11 @@ void Tree::saveToFile() const bool Tree::loadFromFile() { - ifstream file(treeName + ".tft", std::ios::binary); + const char* HOME = getenv("HOME"); + string tftDir(HOME); + tftDir += "/.tft"; + + ifstream file(tftDir + '/' + treeName + ".tftb", std::ios::binary); file.read((char*)(&numPeople), sizeof(numPeople)); diff --git a/src/utils.cpp b/src/utils.cpp index 15f2540..a503e3c 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,4 +1,26 @@ #include "utils.hpp" +#include "person.hpp" +#include + +void init() +{ + setlocale(LC_ALL, "en_US.UTF-8"); + + /* Init ncurses */ + initscr(); /* Start curses mode */ + curs_set(0); /* Hide cursor */ + noecho(); + cbreak(); /* get input instantly */ + keypad(stdscr, true); + start_color(); + use_default_colors(); + /* init_pair(5, COLOR_BLACK, COLOR_BLACK); */ + /* bkgd(COLOR_PAIR(5)); */ + init_pair(COLOR_MALE, COLOR_CYAN, -1); /* -1 means use default */ + init_pair(COLOR_FEMALE, COLOR_RED, -1); + init_pair(COLOR_SELECTED, COLOR_YELLOW, -1); + wnoutrefresh(stdscr); /* if not present the first real refresh is missed */ +} bool willBeVisible(I16 drawY, I16 drawX, U16 height, U16 width) { diff --git a/src/utils.hpp b/src/utils.hpp index c61c860..5a9a402 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -23,6 +23,8 @@ /* return lhs; */ /* } */ +void init(); + template void remove(Vec& vec, size_t pos) /* Remove from vector by moving the last element in its place */ { diff --git a/create_tree.sh b/tft_create similarity index 87% rename from create_tree.sh rename to tft_create index 0090d62..5d5f6b5 100755 --- a/create_tree.sh +++ b/tft_create @@ -24,7 +24,7 @@ language=' 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 +g++ -o "$start_dir/${1%.*}.tft" $language $warnings -march=native -DNDEBUG -pipe -g create_tree.cpp tree.cpp person.cpp utils.cpp -lncursesw rm user_tree.hpp cd "$start_dir" exec "./${1%.*}.tft" diff --git a/todo.txt b/todo.txt index a94fcba..aea56bc 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,4 @@ -Help +--help findRelative