diff --git a/main.cpp b/main.cpp index af82879..e41e332 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,21 @@ -#include +/* +This file is part of CommSyFuse. + +pilang is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +pilang is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with pilang. If not, see . +*/ + +#include #include #include #include @@ -22,6 +39,7 @@ static std::string server_sid; static std::string room; + void panic(std::string message) { std::cerr << std::endl << "An unhandled exception occured:" << std::endl << message << std::endl; abort(); @@ -285,8 +303,16 @@ std::string get_rss_url(GumboNode *node) { // Currently unused int main(int argc, char *argv[]) { + // Show license note if --license was given as first argument + if (argc > 1 and !strncmp(argv[1], "--license", 9)) { + std::cout << "CommSyFuse Copyright (C) 2020 niansa" << std::endl; + std::cout << "This program comes with ABSOLUTELY NO WARRANTY; for details type `warranty'." << std::endl; + std::cout << "This is free software, and you are welcome to redistribute it" << std::endl; + std::cout << "under certain conditions; type `license' for details." << std::endl; + return 0; + } // Check arguments - if (argc < 2) { + if (argc < 3) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return 1; } @@ -345,13 +371,26 @@ int main(int argc, char *argv[]) { std::cout << numposts << ") " << postsmap_numname[numposts] << " – " << postsmap_nummeta[numposts] << std::endl; numposts++; } + std::cout << "r) Refresh" << std::endl; // Debug CLI + std::string userinstr; unsigned long userin; while (true) { // Await user input std::cout << "? " << std::flush; - std::cin >> userin; - // Check if input is valid + std::getline (std::cin,userinstr); + // Check string input options first5 + if (userinstr == "r") { + execve(argv[0], argv, nullptr); + } + // Try to convert input to unsigned long + try { + userin = std::stoul(userinstr,nullptr,0); + } catch (const std::invalid_argument &) { + std::cerr << "Invalid input" << std::endl; + continue; + } + // Check if givenn number is valid if (userin >= numposts) { std::cerr << "No such post" << std::endl; continue;