# HG changeset patch # User Teemu Piippo # Date 1611769154 -7200 # Node ID 94c67ae846fc03910971aa9ecf6f920a0480d8b7 # Parent 2e6cbacafdc7ef9080ca34780f36466f58fdbf77 handle exiting ZFC without using exceptions diff -r 2e6cbacafdc7 -r 94c67ae846fc sources/basics.h --- a/sources/basics.h Wed Jan 27 19:32:55 2021 +0200 +++ b/sources/basics.h Wed Jan 27 19:39:14 2021 +0200 @@ -125,8 +125,6 @@ return N; } -struct Exitception {}; - #ifdef __GNUC__ # define GNUATTRIBUTE(X) __attribute__(X) #else diff -r 2e6cbacafdc7 -r 94c67ae846fc sources/interface.cpp --- a/sources/interface.cpp Wed Jan 27 19:32:55 2021 +0200 +++ b/sources/interface.cpp Wed Jan 27 19:39:14 2021 +0200 @@ -199,6 +199,11 @@ m_needRefresh = false; } +Interface::~Interface() +{ + ::endwin(); +} + // ------------------------------------------------------------------------------------------------- // void Interface::renderTitlebar() @@ -628,7 +633,7 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::handleInput() +void Interface::handleInput(bool* shouldquit) { int ch = ::getch(); @@ -679,8 +684,7 @@ } else { - endwin(); - throw Exitception(); + *shouldquit = true; } }); break; @@ -833,7 +837,7 @@ case INPUTSTATE_NORMAL: if (getCurrentInput()[0] == '/') { - handleCommand(getCurrentInput()); + handleCommand(getCurrentInput(), shouldquit); flushInput(); } else if (m_session.sendCommand(getCurrentInput())) @@ -1052,7 +1056,7 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::handleCommand(const std::string& input) +void Interface::handleCommand(const std::string& input, bool* shouldquit) { if (input[0] != '/') return; @@ -1079,8 +1083,7 @@ else if (command == "quit") { m_session.disconnect(); - endwin(); - throw Exitception(); + *shouldquit = true; } else printError("Unknown command: %s\n", command.data()); diff -r 2e6cbacafdc7 -r 94c67ae846fc sources/interface.h --- a/sources/interface.h Wed Jan 27 19:32:55 2021 +0200 +++ b/sources/interface.h Wed Jan 27 19:39:14 2021 +0200 @@ -49,11 +49,12 @@ }; Interface(); + virtual ~Interface(); void connect(std::string address, std::string password); void disconnected(); RCONSession* getSession() { return &m_session; } - void handleCommand(const std::string& input); - void handleInput(); + void handleCommand(const std::string& input, bool *shouldquit); + void handleInput(bool *shouldquit); void needRefresh(); void __cdecl print(const char* fmtstr, ...) GNUATTRIBUTE((format(printf, 2, 3))); void __cdecl printWarning(const char* fmtstr, ...) GNUATTRIBUTE((format(printf, 2, 3))); diff -r 2e6cbacafdc7 -r 94c67ae846fc sources/main.cpp --- a/sources/main.cpp Wed Jan 27 19:32:55 2021 +0200 +++ b/sources/main.cpp Wed Jan 27 19:39:14 2021 +0200 @@ -72,35 +72,33 @@ if (argc == 3) iface.connect (argv[1], argv[2]); - try + for (;;) { - for (;;) + fd_set fdset; + timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 250000; // 0.25 seconds + FD_ZERO(&fdset); + FD_SET(0, &fdset); + const int fd = iface.getSession()->getSocket()->file_descriptor; + FD_SET(fd, &fdset); + ::select(fd + 1, &fdset, nullptr, nullptr, &timeout); + bool shouldquit = false; + if (FD_ISSET(0, &fdset)) { - fd_set fdset; - int highest = 0; - timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 250000; // 0.25 seconds - FD_ZERO (&fdset); - FD_SET (0, &fdset); - - int fd = iface.getSession()->getSocket()->file_descriptor; - highest = zfc::max (highest, fd); - FD_SET (fd, &fdset); - - select (highest + 1, &fdset, nullptr, nullptr, &timeout); - - if (FD_ISSET (0, &fdset)) - { - // stdin is ready, what's incoming? - iface.handleInput(); - } - + // stdin is ready, what's incoming? + iface.handleInput(&shouldquit); + } + if (shouldquit) + { + break; + } + else + { iface.getSession()->tick(); iface.render(); } } - catch (const zfc::Exitception&) {} iface.getSession()->disconnect(); return EXIT_SUCCESS;