summaryrefslogtreecommitdiffstats
path: root/argument.cpp
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2016-10-06 10:15:48 -0500
committerMatthew Barth <msbarth@us.ibm.com>2016-10-13 16:09:09 -0500
commit6292aeed77cb97a069655d80c37d3587d0846bad (patch)
tree79cbaa6fa696f26b79f9ee4615c563d73c0d5f2b /argument.cpp
parent1f1b41ed8e1be794e51559abf14db9dad3e2bcdc (diff)
downloadphosphor-hwmon-6292aeed77cb97a069655d80c37d3587d0846bad.tar.gz
phosphor-hwmon-6292aeed77cb97a069655d80c37d3587d0846bad.zip
Convert build process to autotools
Replaced the use of a manual Makefile with the use of autotools to automatically verify and generate the necessary build files. Follow the steps outlined within the README.md file to build the package. Change-Id: Ieed870c63b2bef83b3741dd22e413c25916ed408 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'argument.cpp')
-rw-r--r--argument.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/argument.cpp b/argument.cpp
new file mode 100644
index 0000000..e2ae471
--- /dev/null
+++ b/argument.cpp
@@ -0,0 +1,58 @@
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+#include <cassert>
+#include "argument.hpp"
+
+ArgumentParser::ArgumentParser(int argc, char** argv)
+{
+ int option = 0;
+ while(-1 != (option = getopt_long(argc, argv, optionstr, options, NULL)))
+ {
+ if ((option == '?') || (option == 'h'))
+ {
+ usage(argv);
+ exit(-1);
+ }
+
+ auto i = &options[0];
+ while ((i->val != option) && (i->val != 0)) ++i;
+
+ if (i->val)
+ arguments[i->name] = (i->has_arg ? optarg : true_string);
+ }
+}
+
+const std::string& ArgumentParser::operator[](const std::string& opt)
+{
+ auto i = arguments.find(opt);
+ if (i == arguments.end())
+ {
+ return empty_string;
+ }
+ else
+ {
+ return i->second;
+ }
+}
+
+void ArgumentParser::usage(char** argv)
+{
+ std::cerr << "Usage: " << argv[0] << " [options]" << std::endl;
+ std::cerr << "Options:" << std::endl;
+ std::cerr << " --help print this menu" << std::endl;
+ std::cerr << " --path=<path> sysfs location to monitor"
+ << std::endl;
+}
+
+const option ArgumentParser::options[] =
+{
+ { "path", required_argument, NULL, 'p' },
+ { "help", no_argument, NULL, 'h' },
+ { 0, 0, 0, 0},
+};
+
+const char* ArgumentParser::optionstr = "p:?h";
+
+const std::string ArgumentParser::true_string = "true";
+const std::string ArgumentParser::empty_string = "";
OpenPOWER on IntegriCloud