diff --git a/src/parser.cpp b/src/parser.cpp index 0942600..333908b 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -101,7 +101,6 @@ namespace /* internal */ { endwin(); cerr << "Unexpected end of file\n"; - cerr.flush(); exit(1); } @@ -109,7 +108,6 @@ namespace /* internal */ { endwin(); cerr << "Line " << line << ": Unexpected '" << c << "'\n"; - cerr.flush(); exit(1); } @@ -119,7 +117,6 @@ namespace /* internal */ cerr << "Line " << line << ": Expected " << what << " got "; cerr.write(instead.begin, instead.size()); cerr << " instead\n"; - cerr.flush(); exit(1); } @@ -130,7 +127,6 @@ namespace /* internal */ cerr << "Line " << line << ": Unexpected token '"; cerr.write(t.begin, t.size()); cerr << "'\n"; - cerr.flush(); exit(1); } @@ -140,7 +136,6 @@ namespace /* internal */ cerr << "Line " << line << ": Illegal attribute '"; cerr.write(attr.begin, attr.size()); cerr << "'\n"; - cerr.flush(); exit(1); } @@ -149,7 +144,6 @@ namespace /* internal */ /* endwin(); */ /* cerr << "Line " << line << ": two parents are already defined, " */ /* << extra_name << " is third\n"; */ - /* cerr.flush(); */ /* exit(1); */ /* } */ @@ -158,7 +152,6 @@ namespace /* internal */ endwin(); cerr << "Line " << line << ": '" << name << "' is undefined.\n" "Members need to be defined before they are used as relations\n"; - cerr.flush(); exit(1); } @@ -169,7 +162,6 @@ namespace /* internal */ << "At most the index after a name can be the number of people with the " "same name already defined - 1, since the count starts from 0.\n" "In this case the max is " << max << '\n'; - cerr.flush(); exit(1); } diff --git a/src/person.cpp b/src/person.cpp index 8a85626..ee4d21b 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -9,44 +9,42 @@ using std::cout; using std::string; -static WINDOW* info_tab; - EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute) - : year(Year) - , month(Month) - , day(Day) - , hour(Hour) - , minute(Minute) + : year(Year) + , month(Month) + , day(Day) + , hour(Hour) + , minute(Minute) { - assert(month <= 12 && day <= 31 && hour <= 23 && minute <= 59 && "Invalid EventTime data"); + assert(month <= 12 && day <= 31 && hour <= 23 && minute <= 59 && "Invalid EventTime data"); } -void EventTime::print() const +void EventTime::print(WINDOW* info_tab) const { - if (day != UNKNOWN_DATE) - wprintw(info_tab, "%d", day); - else - waddstr(info_tab, "??"); - waddch(info_tab, '.'); + if (day != UNKNOWN_DATE) + wprintw(info_tab, "%d", day); + else + waddstr(info_tab, "??"); + waddch(info_tab, '.'); - if (month != UNKNOWN_DATE) - wprintw(info_tab, "%d", month); - else - waddstr(info_tab, "??"); - waddch(info_tab, '.'); + if (month != UNKNOWN_DATE) + wprintw(info_tab, "%d", month); + else + waddstr(info_tab, "??"); + waddch(info_tab, '.'); - if (year != UNKNOWN_DATE) - wprintw(info_tab, "%d", year); - else - waddstr(info_tab, "????"); - waddch(info_tab, '\n'); + if (year != UNKNOWN_DATE) + wprintw(info_tab, "%d", year); + else + waddstr(info_tab, "????"); + waddch(info_tab, '\n'); } Person::Person(const char* aName, EventTime aBirth, Sex aSex, EventTime aDeath) : name(aName) , birth(aBirth) - , sex(aSex) + , sex(aSex) , death(aDeath) { } @@ -54,21 +52,24 @@ Person::Person(const char* aName, EventTime aBirth, Sex aSex, EventTime aDeath) bool Person::operator==(const Person &other)const { - return name == other.name; //&& sex == other.sex; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year); + return sex == other.sex && name == other.name && + (birth.day == other.birth.day || birth.day == EventTime::UNKNOWN_DATE || other.birth.day == EventTime::UNKNOWN_DATE) && + (birth.month == other.birth.month || birth.month == EventTime::UNKNOWN_DATE || other.birth.month == EventTime::UNKNOWN_DATE) && + (birth.year == other.birth.year || birth.year == EventTime::UNKNOWN_DATE || other.birth.year == EventTime::UNKNOWN_DATE); } void Person::displayInfo()const { - info_tab = newwin(LINES, COLS, 0, 0); + WINDOW* info_tab = newwin(LINES, COLS, 0, 0); waddstr(info_tab, name.data()); waddch(info_tab,'\n'); waddstr(info_tab, "Birth: "); - birth.print(); + birth.print(info_tab); waddstr(info_tab, "Death: "); - death.print(); + death.print(info_tab); mvwaddstr(info_tab, LINES-1, 0, "Press any key to return."); diff --git a/src/person.hpp b/src/person.hpp index 748a7a2..79f1e2e 100644 --- a/src/person.hpp +++ b/src/person.hpp @@ -11,7 +11,7 @@ struct EventTime enum: I8 { UNKNOWN_TIME=-1 }; EventTime(I16 Year=UNKNOWN_DATE, U8 Month=UNKNOWN_DATE, U16 Day=UNKNOWN_DATE, I8 Hour=UNKNOWN_TIME, I8 Minute=UNKNOWN_TIME); - void print() const; + void print(WINDOW*) const; I16 year; //The year in relation to Chritst's birth - 1 (AD) is the year He was born, -1 (BC) is the previous year. There is no year 0 U8 month; diff --git a/src/tft.cpp b/src/tft.cpp index dfabd9f..a266525 100644 --- a/src/tft.cpp +++ b/src/tft.cpp @@ -14,22 +14,38 @@ int main(int argc, char* argv[]) { if(argc < 2) { - cout << "Usage: tft FILE...\n"; + cout << "Usage: tft FILES...\n"; return 0; } if(!strcmp(argv[1], "--help")) { - cout << "Usage: tft FILE...\n" - << "Display the family tree in each FILE\n"; + cout << "Usage: tft FILES...\n" + << "Display the combined family tree in the FILES\n"; return 0; } - init(); - for(int i = 1; i < argc; ++i) + Tree tree( parseTftFile(argv[1]) ); + /* bool negative = false; */ + + for(int i = 2; i < argc; ++i) { - parseTftFile(argv[i]).display(); + tree += parseTftFile(argv[i]); + /* if( !strcmp(argv[i], "-") ) */ + /* { */ + /* negative = true; */ + /* } */ + /* else */ + /* { */ + /* if(negative) */ + /* tree -= parseTftFile(argv[i]); */ + /* else */ + /* tree += parseTftFile(argv[i]); */ + /* } */ } + init(); + tree.display(); + return 0; } diff --git a/src/tree.cpp b/src/tree.cpp index 25c89c9..d9b37e2 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -61,9 +61,6 @@ Tree& Tree::operator+=(const Tree& other) { if(newId[rel.id] >= initNum) /* not already in I */ relations[idIn1].push_back( {newId[rel.id], rel.type} ); - else - { - } } } diff --git a/src/utils.cpp b/src/utils.cpp index b748bc6..becb9e6 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -6,24 +6,6 @@ #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"<0 ? 0 : -drawX; pnoutrefresh(pad, - pbegY, pbegX, - drawY, drawX, - LINES - 1, COLS - 1); + pbegY, pbegX, + drawY, drawX, + LINES - 1, COLS - 1); }