]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/Arguments.cpp
added argument interpreter
[l2e.git] / src / app / Arguments.cpp
diff --git a/src/app/Arguments.cpp b/src/app/Arguments.cpp
new file mode 100644 (file)
index 0000000..bdfdf18
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Arguments.cpp
+ *
+ *  Created on: Sep 15, 2012
+ *      Author: holy
+ */
+
+#include "Arguments.h"
+
+#include <stdexcept>
+#include <string>
+
+namespace app {
+
+Arguments::Arguments()
+: outfile(0) {
+
+}
+
+
+void Arguments::Read(int argc, char **argv) {
+       for (int i(1); i < argc; ++i) {
+               char *arg(argv[i]);
+               if (arg[0] == '-') {
+                       switch (arg[1]) {
+                               case 'o':
+                                       if (i + 1 >= argc) {
+                                               throw std::runtime_error("missing argument to -o");
+                                       }
+                                       ++i;
+                                       outfile = argv[i];
+                                       break;
+                               default:
+                                       throw std::runtime_error(std::string("unknown option ") + arg[1]);
+                                       break;
+                       }
+               } else {
+                       infiles.push_back(arg);
+               }
+       }
+}
+
+}