3 #include <cstring> // strrchr
7 #include <unistd.h> // getopt
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
15 const char* program_name;
17 const char* platform_file;
18 const char* application_file;
20 int help_requested = 0;
21 bool version_requested = false;
23 unsigned log_rate = 1;
26 bool exit_on_close = false;
28 bool bookkeeping = false;
30 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
36 const char* on_off(bool b)
38 return b ? "on" : "off";
43 int opt::parse_args(int* argc, char* argv[])
47 char* tmp = strrchr(argv[0], '/');
48 opt::program_name = (tmp ? tmp + 1 : argv[0]);
52 while ((c = getopt(*argc, argv, "bc:ehi:l:V")) != -1) {
55 opt::bookkeeping = true;
58 opt::exit_on_close = true;
61 opt::help_requested++;
64 opt::comp_cost = cost_func(optarg);
67 std::istringstream(optarg) >> opt::maxiter;
70 std::istringstream(optarg) >> opt::log_rate;
73 opt::version_requested = true;
76 ERROR1("invalid option -- '%c'", optopt);
81 if (opt::version_requested || opt::help_requested)
84 int rem_args = *argc - optind;
87 ERROR0("missing parameter -- <plaform_file>");
89 ERROR0("missing parameter -- <application_file>");
94 opt::platform_file = argv[optind];
95 opt::application_file = argv[optind + 1];
98 for (int i = optind + 2 ; i < *argc ; ++i)
99 ERROR1("unused parameter -- \"%s\"", argv[i]);
109 INFO0(",----[ Simulation parameters ]");
110 INFO1("| platform_file.......: \"%s\"", opt::platform_file);
111 INFO1("| application_file....: \"%s\"", opt::application_file);
112 INFO1("| log rate............: %u", opt::log_rate);
113 INFO1("| maxiter.............: %u", opt::maxiter);
114 INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
115 INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
116 INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str());
122 const int indent1 = 6;
123 const int indent2 = 12;
125 #define oo(opt, arg) std::setw(indent1) << (opt) << " " \
126 << std::setw(indent2) << std::left << (arg) << std::right
127 #define o(opt) oo(opt, "")
129 std::clog << "Usage: " << opt::program_name
130 << " [options] <platform_file> <application_file>\n";
133 << "print help and exit (use -hh or -hhh for extended help)\n";
134 if (opt::help_requested < 1)
137 std::clog << o("-V") << "print version and exit\n";
139 std::clog << o("-b") << "activate bookkeeping\n";
140 std::clog << oo("-c", "[fn,...]f0")
141 << "polynomial factors for computation cost ("
142 << opt::comp_cost.to_string() << ")\n";
143 std::clog << o("-e") << "exit on close reception\n";
144 std::clog << oo("-i", "value")
145 << "maximum number of iterations, 0 for infinity ("
146 << opt::maxiter << ")\n";
147 std::clog << oo("-l", "value")
148 << "print current load every \"value\" iterations, 0 to disable ("
149 << opt::log_rate << ")\n";