1 #include <cstring> // strrchr
5 #include <unistd.h> // getopt
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
14 const char* program_name;
16 const char* platform_file;
17 const char* application_file;
19 int help_requested = 0;
20 bool version_requested = false;
23 bool exit_on_close = false;
25 bool bookkeeping = false;
27 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
33 const char* on_off(bool b)
35 return b ? "on" : "off";
40 int opt::parse_args(int* argc, char* argv[])
44 char* tmp = strrchr(argv[0], '/');
45 opt::program_name = (tmp ? tmp + 1 : argv[0]);
49 while ((c = getopt(*argc, argv, "bc:ehi:V")) != -1) {
52 opt::bookkeeping = true;
55 opt::exit_on_close = true;
58 opt::help_requested++;
61 opt::comp_cost = cost_func(optarg);
64 std::istringstream(optarg) >> opt::maxiter;
67 opt::version_requested = true;
70 ERROR1("invalid option -- '%c'", optopt);
75 if (opt::version_requested || opt::help_requested)
78 int rem_args = *argc - optind;
81 ERROR0("missing parameter -- <plaform_file>");
83 ERROR0("missing parameter -- <application_file>");
88 opt::platform_file = argv[optind];
89 opt::application_file = argv[optind + 1];
92 for (int i = optind + 2 ; i < *argc ; ++i)
93 ERROR1("unused parameter -- \"%s\"", argv[i]);
103 INFO0(",----[ Simulation parameters ]");
104 INFO1("| platform_file.......: \"%s\"", opt::platform_file);
105 INFO1("| application_file....: \"%s\"", opt::application_file);
106 INFO1("| maxiter.............: %u", opt::maxiter);
107 INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
108 INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
109 INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str());
115 const int indent1 = 6;
116 const int indent2 = 12;
118 #define oo(opt, arg) std::setw(indent1) << (opt) << " " \
119 << std::setw(indent2) << std::left << (arg) << std::right
120 #define o(opt) oo(opt, "")
122 std::clog << "Usage: " << opt::program_name
123 << " [options] <platform_file> <application_file>\n";
126 << "print help and exit (use -hh or -hhh for extended help)\n";
127 if (opt::help_requested < 1)
130 std::clog << o("-V") << "print version and exit\n";
132 std::clog << o("-b") << "activate bookkeeping\n";
133 std::clog << oo("-c", "[fn,...]f0")
134 << "polynomial factors for computation cost ("
135 << opt::comp_cost.to_string() << ")\n";
136 std::clog << o("-e") << "exit on close reception\n";
137 std::clog << oo("-i", "value")
138 << "maximum number of iterations, 0 for infinity ("
139 << opt::maxiter << ")\n";