X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/147d0e88c4da14c801d15e0875bedb474180bea2..5279f43fc9be71815091e79c76d5bc04c8c88421:/options.cpp diff --git a/options.cpp b/options.cpp index 24ae952..18d4613 100644 --- a/options.cpp +++ b/options.cpp @@ -1,6 +1,8 @@ -#include +#include // strrchr +#include #include -#include +#include +#include // getopt #include #include "options.h" #include "misc.h" @@ -17,56 +19,83 @@ namespace opt { int help_requested = 0; bool version_requested = false; + unsigned maxiter = 4; + bool exit_on_close = false; + + bool bookkeeping = false; + cost_func comp_cost("1e9, 0"); // fixme: find better defaults - cost_func comm_cost("1e9, 0"); // fixme: find better defaults } // namespace opt +namespace { + + const char* on_off(bool b) + { + return b ? "on" : "off"; + } + +} + int opt::parse_args(int* argc, char* argv[]) { - char *tmp = strrchr(argv[0], '/'); + int result = 1; + + char* tmp = strrchr(argv[0], '/'); opt::program_name = (tmp ? tmp + 1 : argv[0]); int c; opterr = 0; - while ((c = getopt(*argc, argv, "hc:C:V")) != -1) { + while ((c = getopt(*argc, argv, "bc:ehi:V")) != -1) { switch (c) { + case 'b': + opt::bookkeeping = true; + break; + case 'e': + opt::exit_on_close = true; + break; case 'h': opt::help_requested++; break; case 'c': opt::comp_cost = cost_func(optarg); break; - case 'C': - opt::comm_cost = cost_func(optarg); + case 'i': + std::istringstream(optarg) >> opt::maxiter; break; case 'V': opt::version_requested = true; break; case '?': - WARN1("invalid option -- '%c'", optopt); + ERROR1("invalid option -- '%c'", optopt); + result = 0; break; } } if (opt::version_requested || opt::help_requested) return 1; - switch (*argc - optind) { + int rem_args = *argc - optind; + switch (rem_args) { case 0: ERROR0("missing parameter -- "); case 1: ERROR0("missing parameter -- "); - return 0; + result = 0; + break; default: opt::platform_file = argv[optind]; opt::application_file = argv[optind + 1]; + if (rem_args == 2) + break; for (int i = optind + 2 ; i < *argc ; ++i) - WARN1("unused parameter -- \"%s\"", argv[i]); + ERROR1("unused parameter -- \"%s\"", argv[i]); + result = 0; break; } - return 1; + return result; } void opt::print() @@ -74,12 +103,13 @@ void opt::print() INFO0(",----[ Simulation parameters ]"); INFO1("| platform_file.......: \"%s\"", opt::platform_file); INFO1("| application_file....: \"%s\"", opt::application_file); - INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str()); - INFO1("| comm. cost factors..: [%s]", opt::comm_cost.to_string().c_str()); + INFO1("| maxiter.............: %u", opt::maxiter); + INFO1("| exit on close.......: %s", on_off(opt::exit_on_close)); + INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping)); + INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str()); INFO0("`----"); } -#include void opt::usage() { const int indent1 = 6; @@ -96,13 +126,17 @@ void opt::usage() << "print help and exit (use -hh or -hhh for extended help)\n"; if (opt::help_requested < 1) return; + std::clog << o("-V") << "print version and exit\n"; + + std::clog << o("-b") << "activate bookkeeping\n"; std::clog << oo("-c", "[fn,...]f0") << "polynomial factors for computation cost (" << opt::comp_cost.to_string() << ")\n"; - std::clog << oo("-C", "[fn,...]f0") - << "polynomial factors for communication cost (" - << opt::comm_cost.to_string() << ")\n"; + std::clog << o("-e") << "exit on close reception\n"; + std::clog << oo("-i", "value") + << "maximum number of iterations, 0 for infinity (" + << opt::maxiter << ")\n"; #undef o #undef oo