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;
22 unsigned log_rate = 1;
25 bool exit_on_close = false;
27 bool bookkeeping = false;
29 cost_func comp_cost("1e9, 0"); // fixme: find better defaults
35 const char* on_off(bool b)
37 return b ? "on" : "off";
42 int opt::parse_args(int* argc, char* argv[])
46 char* tmp = strrchr(argv[0], '/');
47 opt::program_name = (tmp ? tmp + 1 : argv[0]);
51 while ((c = getopt(*argc, argv, "bc:ehi:l:V")) != -1) {
54 opt::bookkeeping = true;
57 opt::exit_on_close = true;
60 opt::help_requested++;
63 opt::comp_cost = cost_func(optarg);
66 std::istringstream(optarg) >> opt::maxiter;
69 std::istringstream(optarg) >> opt::log_rate;
72 opt::version_requested = true;
75 ERROR1("invalid option -- '%c'", optopt);
80 if (opt::version_requested || opt::help_requested)
83 int rem_args = *argc - optind;
86 ERROR0("missing parameter -- <plaform_file>");
88 ERROR0("missing parameter -- <application_file>");
93 opt::platform_file = argv[optind];
94 opt::application_file = argv[optind + 1];
97 for (int i = optind + 2 ; i < *argc ; ++i)
98 ERROR1("unused parameter -- \"%s\"", argv[i]);
108 INFO0(",----[ Simulation parameters ]");
109 INFO1("| platform_file.......: \"%s\"", opt::platform_file);
110 INFO1("| application_file....: \"%s\"", opt::application_file);
111 INFO1("| log rate............: %u", opt::log_rate);
112 INFO1("| maxiter.............: %u", opt::maxiter);
113 INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
114 INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
115 INFO1("| comp. cost factors..: [%s]", opt::comp_cost.to_string().c_str());
121 const int indent1 = 6;
122 const int indent2 = 12;
124 #define oo(opt, arg) std::setw(indent1) << (opt) << " " \
125 << std::setw(indent2) << std::left << (arg) << std::right
126 #define o(opt) oo(opt, "")
128 std::clog << "Usage: " << opt::program_name
129 << " [options] <platform_file> <application_file>\n";
132 << "print help and exit (use -hh or -hhh for extended help)\n";
133 if (opt::help_requested < 1)
136 std::clog << o("-V") << "print version and exit\n";
138 std::clog << o("-b") << "activate bookkeeping\n";
139 std::clog << oo("-c", "[fn,...]f0")
140 << "polynomial factors for computation cost ("
141 << opt::comp_cost.to_string() << ")\n";
142 std::clog << o("-e") << "exit on close reception\n";
143 std::clog << oo("-i", "value")
144 << "maximum number of iterations, 0 for infinity ("
145 << opt::maxiter << ")\n";
146 std::clog << oo("-l", "value")
147 << "print current load every \"value\" iterations, 0 to disable ("
148 << opt::log_rate << ")\n";