+#include <cstring>
+#include <iostream>
+#include <unistd.h>
+#include <xbt/log.h>
+#include "options.h"
+#include "misc.h"
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
+
+namespace opt {
+
+ const char* program_name;
+
+ const char* platform_file;
+ const char* application_file;
+
+ int help_requested = 0;
+ bool version_requested = false;
+
+ cost_func comp_cost("1, 0");
+ cost_func comm_cost("1, 0");
+
+} // namespace opt
+
+int opt::parse_args(int* argc, char* argv[])
+{
+ 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) {
+ switch (c) {
+ case 'h':
+ opt::help_requested++;
+ break;
+ case 'c':
+ opt::comp_cost = cost_func(optarg);
+ break;
+ case 'C':
+ opt::comm_cost = cost_func(optarg);
+ break;
+ case 'V':
+ opt::version_requested = true;
+ break;
+ case '?':
+ WARN1("invalid option -- '%c'", optopt);
+ break;
+ }
+ }
+ if (opt::version_requested || opt::help_requested)
+ return 1;
+
+ switch (*argc - optind) {
+ case 0:
+ ERROR0("missing parameter -- <plaform_file>");
+ case 1:
+ ERROR0("missing parameter -- <application_file>");
+ return 0;
+
+ default:
+ opt::platform_file = argv[optind];
+ opt::application_file = argv[optind + 1];
+ for (int i = optind + 2 ; i < *argc ; ++i)
+ WARN1("unused parameter -- \"%s\"", argv[i]);
+ break;
+ }
+
+ return 1;
+}
+
+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());
+ INFO0("`----");
+}
+
+#include <iomanip>
+void opt::usage()
+{
+ const int indent1 = 6;
+ const int indent2 = 12;
+
+#define oo(opt, arg) std::setw(indent1) << (opt) << " " \
+ << std::setw(indent2) << std::left << (arg) << std::right
+#define o(opt) oo(opt, "")
+
+ std::clog << "Usage: " << opt::program_name
+ << " [options] <platform_file> <application_file>\n";
+
+ std::clog << o("-h")
+ << "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 << 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";
+
+#undef o
+#undef oo
+}
+
+// Local variables:
+// mode: c++
+// End: