| 2371 | } |
| 2372 | |
| 2373 | Param TOPPBase::parseCommandLine_(const int argc, const char** argv, const String& misc, const String& unknown) |
| 2374 | { |
| 2375 | Param cmd_params; |
| 2376 | |
| 2377 | // current state: |
| 2378 | // 'parameters_' contains all commandline params which were registered using 'registerOptionsAndFlags_()' + the common ones (-write_ini etc) |
| 2379 | // .. they are empty/default at this point |
| 2380 | // We now fetch the (so-far unknown) subsection parameters (since they can be addressed on command line as well) |
| 2381 | |
| 2382 | // special case of GenericWrapper: since we need the subSectionDefaults before pushing the cmd arguments in there |
| 2383 | // but the 'type' is empty currently, |
| 2384 | // we extract and set it beforehand |
| 2385 | StringList sl_args = StringList(argv, argv + argc); |
| 2386 | StringList::iterator it_type = std::find(sl_args.begin(), sl_args.end(), "-type"); |
| 2387 | if (it_type != sl_args.end()) |
| 2388 | { // found it |
| 2389 | ++it_type; // advance to next argument -- this should be the value of -type |
| 2390 | if (it_type != sl_args.end()) param_.setValue("type", *it_type); |
| 2391 | } |
| 2392 | |
| 2393 | // prepare map of parameters: |
| 2394 | typedef map<String, vector<ParameterInformation>::const_iterator> ParamMap; |
| 2395 | ParamMap param_map; |
| 2396 | for (vector<ParameterInformation>::const_iterator it = parameters_.begin(); it != parameters_.end(); ++it) |
| 2397 | { |
| 2398 | param_map["-" + it->name] = it; |
| 2399 | } |
| 2400 | |
| 2401 | vector<ParameterInformation> subsection_param; |
| 2402 | try |
| 2403 | { |
| 2404 | // the parameters from the subsections |
| 2405 | subsection_param = paramToParameterInformation_(getSubsectionDefaults_()); |
| 2406 | for (vector<ParameterInformation>::const_iterator it = subsection_param.begin(); it != subsection_param.end(); ++it) |
| 2407 | { |
| 2408 | param_map["-" + it->name] = it; |
| 2409 | } |
| 2410 | } |
| 2411 | catch (BaseException& e) |
| 2412 | { // this only happens for GenericWrapper, if 'type' is not given or invalid (then we do not have subsection params) -- enough to issue a warning |
| 2413 | writeLogWarn_(String("Warning: Unable to fetch subsection parameters! Addressing subsection parameters will not work for this tool (did you forget to specify '-type'?).")); |
| 2414 | writeDebug_(String("Error occurred in line ") + e.getLine() + " of file " + e.getFile() + " (in function: " + e.getFunction() + ")!", 1); |
| 2415 | } |
| 2416 | |
| 2417 | // list to store "misc"/"unknown" items: |
| 2418 | map<std::string, std::vector<std::string> > misc_unknown; |
| 2419 | |
| 2420 | list<String> queue; // queue for arguments |
| 2421 | // we parse the arguments in reverse order, so that we have arguments already when we encounter the option that uses them! |
| 2422 | for (int i = argc - 1; i > 0; --i) |
| 2423 | { |
| 2424 | String arg = argv[i]; |
| 2425 | // options start with "-" or "--" followed by a letter: |
| 2426 | bool is_option = (arg.size() >= 2) && (arg[0] == '-') && (isalpha(arg[1]) || ((arg[1] == '-') && (arg.size() >= 3) && isalpha(arg[2]))); |
| 2427 | if (is_option) // process content of the queue |
| 2428 | { |
| 2429 | ParamMap::iterator pos = param_map.find(arg); |
| 2430 | if (pos != param_map.end()) // parameter is defined |
nothing calls this directly
no test coverage detected