summaryrefslogtreecommitdiffhomepage
path: root/mcc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mcc.cpp')
-rw-r--r--mcc.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/mcc.cpp b/mcc.cpp
index 7d94cf8..bb89d29 100644
--- a/mcc.cpp
+++ b/mcc.cpp
@@ -5,6 +5,7 @@
#include "cpp.h"
#include "elf.h"
#include "file.h"
+#include "programopts.h"
#include <iostream>
@@ -12,23 +13,33 @@ using namespace std::string_literals;
namespace {
-void usage() {
- std::cout << "Usage: mcc <translation_unit>" << std::endl;
-}
+ void usage() {
+ std::cout << "Usage: mcc <translation_unit>" << std::endl;
+ }
}
int main(int argc, char* argv[])
{
+ // Processing of options in lambdas: each do return true iff parameter was consumed
+ std::map<std::string, std::function<bool(const std::string&)>> option_prefixes{
+ {"-h", [&](const std::string& parameter) -> bool { usage(); return false; }},
+ };
+
try {
CPP cpp;
- if (argc != 2) {
+ ProgramOpts options(argc, argv, option_prefixes);
+ options.process();
+
+ std::vector<std::string> parameters {options.nonOptionArguments()};
+
+ if (parameters.size() != 1) {
usage();
return 1;
}
- fs::path in_filename{argv[1]};
+ fs::path in_filename{parameters[0]};
fs::path out_filename{in_filename.parent_path() / in_filename.stem()};
if (in_filename == out_filename)
@@ -48,3 +59,4 @@ int main(int argc, char* argv[])
return 0;
}
+