summaryrefslogtreecommitdiffhomepage
path: root/mcc.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-10-26 15:38:54 +0100
committerRoland Reichwein <mail@reichwein.it>2020-10-26 15:38:54 +0100
commitce77838c4f32b9dc237f0c4b17d1f1e1741254d4 (patch)
treef8b987e81bd94bff0a4035ddfe75d344664ece10 /mcc.cpp
parentaddbdf3cf71c6d332bdf86a101a7df544fe5a9a2 (diff)
Added ProgramOpts
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;
}
+