From ce77838c4f32b9dc237f0c4b17d1f1e1741254d4 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 26 Oct 2020 15:38:54 +0100 Subject: Added ProgramOpts --- mcc.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'mcc.cpp') 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 @@ -12,23 +13,33 @@ using namespace std::string_literals; namespace { -void usage() { - std::cout << "Usage: mcc " << std::endl; -} + void usage() { + std::cout << "Usage: mcc " << std::endl; + } } int main(int argc, char* argv[]) { + // Processing of options in lambdas: each do return true iff parameter was consumed + std::map> 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 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; } + -- cgit v1.2.3