diff --git a/hcore/Makefile.am b/hcore/Makefile.am index 720257a..5822241 100644 --- a/hcore/Makefile.am +++ b/hcore/Makefile.am @@ -1,4 +1,4 @@ AM_CPPFLAGS+= -I"$(top_srcdir)/hcore/include" noinst_LIBRARIES = libhcore.a -libhcore_a_SOURCES = mind.cpp +libhcore_a_SOURCES = mind.cpp opts.cpp diff --git a/hcore/include/opts.h b/hcore/include/opts.h new file mode 100644 index 0000000..eff1ca2 --- /dev/null +++ b/hcore/include/opts.h @@ -0,0 +1,29 @@ +#ifndef OPTS_H +#define OPTS_H + +#include +#include +#include + +// Define a class to hold the options and parse arguments +class OptionParser +{ +public: + OptionParser() : verbose(false) {} + ~OptionParser() = default; + + void parseArguments(int argc, char *argv[]); + void dumpOptions() const; + std::string getUsage() const; + +private: + std::vector extro; + std::vector intero; + std::vector actuator; + std::string devFile; + bool verbose; + + static struct option longOptions[]; +}; + +#endif // OPTS_H diff --git a/hcore/opts.cpp b/hcore/opts.cpp new file mode 100644 index 0000000..991620f --- /dev/null +++ b/hcore/opts.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include + +struct option OptionParser::longOptions[] = { + {"extro", required_argument, 0, 'e'}, + {"extrospector", required_argument, 0, 'e'}, + {"intero", required_argument, 0, 'i'}, + {"interoceptor", required_argument, 0, 'i'}, + {"act", required_argument, 0, 'a'}, + {"actuator", required_argument, 0, 'a'}, + {"devfile", required_argument, 0, 'd'}, + {"devicefile", required_argument, 0, 'd'}, + {"verbose", no_argument, 0, 'v'}, + {0, 0, 0, 0} +}; + +void OptionParser::parseArguments(int argc, char *argv[]) +{ + int opt; + int optionIndex = 0; + optind = 1; // Reset optind to 1 before parsing + while ((opt = getopt_long( + argc, argv, "e:i:a:d:v", longOptions, &optionIndex)) != -1) + { + switch (opt) + { + case 'e': + extro.push_back(optarg); + break; + case 'i': + intero.push_back(optarg); + break; + case 'a': + actuator.push_back(optarg); + break; + case 'd': + devFile = optarg; + break; + case 'v': + verbose = true; + break; + default: + throw std::invalid_argument("Invalid argument encountered: " + std::string(argv[optind - 1])); + } + } +} + +std::string OptionParser::getUsage() const +{ + return "Usage: program [-e|--extro|--extrospector ] " + "[-i|--intero|--interoceptor ] " + "[-a|--act|--actuator ] " + "[-d|--devfile|--devicefile ] " + "[-v|--verbose]"; +} + +void OptionParser::dumpOptions() const +{ + if (verbose) { + std::cout << "Verbose mode is on" << std::endl; + } + + std::cout << "Extro: "; + for (const auto& extro : extro) { + std::cout << extro << " "; + } + std::cout << std::endl; + + std::cout << "Intero: "; + for (const auto& intero : intero) { + std::cout << intero << " "; + } + std::cout << std::endl; + + std::cout << "Actuator: "; + for (const auto& actuator : actuator) { + std::cout << actuator << " "; + } + std::cout << std::endl; + + std::cout << "Dev file: " << devFile << std::endl; +} diff --git a/main.cpp b/main.cpp index 48cd07f..1febc36 100644 --- a/main.cpp +++ b/main.cpp @@ -1,22 +1,31 @@ #include #include +#include #include int main(int argc, char **argv) { +try { + OptionParser options; hk::Mind mind; + std::cout <