From f4ca4211b23a631f8d5b2e5f2e72e13f57593a29 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 8 Mar 2023 20:52:59 +0200 Subject: [PATCH] flush err --- .gitignore | 8 -------- example_tree.tft | 19 +++++++++++++++++++ src/parser.cpp | 33 +++++++++++++++++++++------------ src/utils.cpp | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+), 20 deletions(-) delete mode 100644 .gitignore create mode 100755 example_tree.tft diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 75403b6..0000000 --- a/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -bin -.codelite -*.workspace -GPATH -GRTAGS -GTAGS - -*.tft diff --git a/example_tree.tft b/example_tree.tft new file mode 100755 index 0000000..3ff31e6 --- /dev/null +++ b/example_tree.tft @@ -0,0 +1,19 @@ +# This is a comment +# The dating in this tree is according to the Byzantine calendar but relative to Christ's birth + +Adam, M # Adam is a male +b: -5509.9.06 # Birthday in format yyyy.mm.dd + +Eve, F +b: -5509.9.06 +s: Adam # Eve's spouse is Adam + +Cain, M # Cain's birthday is unknown +p: Adam, Eve,steve # Cain's parents are Adam and Eve + +Abel, M +p: - # Abel's parents are the same as the last person's (Cain) + +Seth, M +b: -5279 +p: - diff --git a/src/parser.cpp b/src/parser.cpp index d72698c..49a468e 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4,17 +4,23 @@ #include "tree.hpp" #include "utils.hpp" -/* macros rather then function to avoid warnings */ -#define ERR_UNEXPECTED_END() { endwin(); cerr << "Unexpected end of file" << endl; exit(1); } -#define ERR_UNEXPECTED_CHAR(c) { endwin(); cerr << "Line " << line << ": Unexpected '" << c << endl; exit(1); } - - using std::cerr; /* using std::string_view; */ using std::string; using std::vector; using std::pair; -using std::endl; +/* using std::endl; */ + +/* macros rather then function to avoid warnings */ +#define ERR_UNEXPECTED_END() { endwin(); \ + cerr << "Unexpected end of file\n"; \ + cerr.flush(); \ + exit(1); } + +#define ERR_UNEXPECTED_CHAR(c) { endwin(); \ + cerr << "Line " << line << ": Unexpected '" << c << "'\n"; \ + cerr.flush(); \ + exit(1); } namespace /* internal */ { @@ -45,11 +51,11 @@ namespace /* internal */ /* result */ Tree* cur_tree; - void err_three_parents(const string& extra_name) + void err_third_parent(const string& extra_name) { endwin(); - cerr << "Line " << line << " two parents are already defined, " - << extra_name << " is third" << endl; + cerr << "Line " << line << ": two parents are already defined, " + << extra_name << " is third\n"; exit(1); } @@ -177,7 +183,7 @@ namespace /* internal */ else if(res.second == Nobody) res.second = cur_tree->findId(name)[same_name_index]; else - err_three_parents(name); + err_third_parent(name); same_name_index = 0; name.clear(); @@ -190,9 +196,12 @@ namespace /* internal */ case '\n': ++line; if(res.first == Nobody) - res.first = cur_tree->findId(name)[same_name_index]; - else + res.first = cur_tree->findId(name)[same_name_index]; /* todo validate index */ + else if(res.second == Nobody) res.second = cur_tree->findId(name)[same_name_index]; + else + err_third_parent(name); + return prev_parents = res; case '_': name.push_back(' '); diff --git a/src/utils.cpp b/src/utils.cpp index cfe36b2..f241fdf 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -6,6 +6,24 @@ #include #include +static void end() +{ + /* printf("before end\n"); */ + /* fflush(stdout); */ + /* for(int i=0;i < 100;i) */ + /* { */ + /* printf("before end\n"); */ + /* fflush(stdout); */ + /* } */ + endwin(); + /* printf("done\n"); */ + /* fflush(stdout); */ + + /* std::cout <<"done\n"<