diff --git a/src/config.hpp b/src/config.hpp index 0c6920f..1de2e1a 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -10,4 +10,4 @@ * Set to 1 to compile and run the test suite */ -#define _TESTS_ 1 +#define _TESTS_ 0 diff --git a/src/main.cpp b/src/main.cpp index 553cad3..9b07100 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ // #include +#include #include "config.hpp" #include "rss.hpp" @@ -12,10 +13,52 @@ #include "tests.hpp" #endif +struct option_flags { + unsigned int title : 1; + unsigned int link : 1; + unsigned int description : 1; + unsigned int language : 1; + unsigned int webmaster : 1; + unsigned int copyright : 1; + unsigned int pubdate : 1; + unsigned int managingeditor : 1; + unsigned int generator : 1; + unsigned int docs : 1; + unsigned int ttl : 1; + unsigned int builddate : 1; + + std::string uri; +}; + +//cli options +static struct option long_options[] = +{ + {"uri", required_argument, 0, 'u'}, + {"title", no_argument, 0, 't'}, + {"link", no_argument, 0, 'l'}, + {"description", no_argument, 0, 'd'}, + {"language", no_argument, 0, 'e'}, + {"webmaster", no_argument, 0, 'm'}, + {"copyright", no_argument, 0, 'c'}, + {"pubdate", no_argument, 0, 'p'}, + {"managingeditor", no_argument, 0, 'q'}, + {"generator", no_argument, 0, 'g'}, + {"docs", no_argument, 0, 'o'}, + {"ttl", no_argument, 0, 'w'}, + {"builddate", no_argument, 0, 'b'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}, +}; + +constexpr char* optarg_string = "u:tldemcpqgowbh"; + void help(char* progName){ std::cout << "Usage: " << progName << "[-u FEED_URI]\n"; std::cout << "Options:\n"; + std::cout << "Required Options:\n"; std::cout << " [-u, --uri] URI of the rss stream\n\n"; + + std::cout << "Channel information:\n"; std::cout << " [-t, --title] Get title of channel\n"; std::cout << " [-l, --link] Get link to channel\n"; std::cout << " [-d, --description] Get Description of channel\n"; @@ -27,21 +70,103 @@ void help(char* progName){ std::cout << " [-g, --generator] Get generator of this feed\n"; std::cout << " [-o, --docs] Get link to RSS documentation\n"; std::cout << " [-w, --ttl] Get ttl, time that channel can be\n"; - std::cout << " cached before being updated\n"; + std::cout << " cached before being updated\n"; std::cout << " [-b, --builddate] Get last time the channel's\n"; - std::cout << " content changed\n"; + std::cout << " content changed\n\n"; + std::cout << "General options:\n"; + std::cout << " [-h, --help] Show this message\n"; + + exit(1); } +option_flags* parse_options(int argc, char** argv) { + int option_index = 0; + int c; + option_flags* ret = new option_flags; + + while(true){ + c = getopt_long(argc, argv, optarg_string, + long_options, &option_index); + if(c == -1) + break; + + switch(c){ + case 'u': + ret->uri = std::string(optarg); + break; + case 't': + ret->title ^= 1; + break; + case 'l': + ret->link ^= 1; + break; + case 'd': + ret->description ^= 1; + break; + case 'e': + ret->language ^= 1; + break; + case 'm': + ret->webmaster ^= 1; + break; + case 'c': + ret->copyright ^= 1; + break; + case 'p': + ret->pubdate ^= 1; + break; + case 'q': + ret->managingeditor ^= 1; + break; + case 'g': + ret->generator ^= 1; + break; + case 'o': + ret->docs ^= 1; + break; + case 'w': + ret->ttl ^= 1; + break; + case 'b': + ret->builddate ^= 1; + break; + case '?': + std::cerr << "Misunderstood flag!" << std::endl; + case 'h': + help(argv[0]); + break; + default: + abort(); + } + } + + if(ret->uri == ""){ + std::cerr << "Missing required option! -u/--uri" << std::endl; + exit(-1); + } + + + return ret; +} + + int main(int argc, char** argv) { #if _TESTS_ == 1 rss_utils::testRSS(); return 0; #endif + //get the passed options + option_flags* opts = parse_options(argc, argv); + + //setup the rss object + + + return 0; }