bool options(int count, char **arg) { int i; bool result = true; if (count == 1) { PrintHelp(); exit(0); } cout.setf(ios_base::fixed); for (i=1; i<count; i++) { string argument = string(arg[i]); string keyword(argument); string value(""); string::size_type n=argument.find("="); if (n != string::npos && n > 0) { keyword = argument.substr(0, n); value = argument.substr(n+1); } if (keyword == "--help") { PrintHelp(); exit(0); } else if (keyword == "--version") { cout << endl << " JSBSim Version: " << FDMExec->GetVersion() << endl << endl; exit (0); } else if (keyword == "--realtime") { realtime = true; } else if (keyword == "--nice") { play_nice = true; } else if (keyword == "--suspend") { suspend = true; } else if (keyword == "--nohighlight") { nohighlight = true; } else if (keyword == "--outputlogfile") { if (n != string::npos) { LogOutputName = value; } else { LogOutputName = "JSBout.csv"; cerr << " Output log file name must be specified with an = sign. Using JSBout.csv as default"; } } else if (keyword == "--logdirectivefile") { if (n != string::npos) { LogDirectiveName.push_back(value); } else { gripe; exit(1); } } else if (keyword == "--root") { if (n != string::npos) { RootDir = value; if (RootDir[RootDir.length()-1] != '/') { RootDir += '/'; } } else { gripe; exit(1); } } else if (keyword == "--aircraft") { if (n != string::npos) { AircraftName = value; } else { gripe; exit(1); } } else if (keyword == "--script") { if (n != string::npos) { ScriptName = value; } else { gripe; exit(1); } } else if (keyword == "--initfile") { if (n != string::npos) { ResetName = value; } else { gripe; exit(1); } } else if (keyword == "--property") { if (n != string::npos) { string propName = value.substr(0,value.find("=")); string propValueString = value.substr(value.find("=")+1); double propValue = atof(propValueString.c_str()); CommandLineProperties.push_back(propName); CommandLinePropertyValues.push_back(propValue); } else { gripe; exit(1); } } else if (keyword == "--end-time") { if (n != string::npos) { try { end_time = atof( value.c_str() ); } catch (...) { cerr << endl << " Invalid end time given!" << endl << endl; result = false; } } else { gripe; exit(1); } } else if (keyword == "--simulation-rate") { if (n != string::npos) { try { simulation_rate = atof( value.c_str() ); override_sim_rate = true; } catch (...) { cerr << endl << " Invalid simulation rate given!" << endl << endl; result = false; } } else { gripe; exit(1); } } else if (keyword == "--catalog") { catalog = true; if (value.size() > 0) AircraftName=value; } else if (keyword.substr(0,2) != "--" && value.empty() ) { // See what kind of files we are specifying on the command line XMLFile xmlFile; if (xmlFile.IsScriptFile(keyword)) ScriptName = keyword; else if (xmlFile.IsLogDirectiveFile(keyword)) LogDirectiveName.push_back(keyword); //else if (xmlFile.IsAircraftFile(keyword)) AircraftName = keyword; //else if (xmlFile.IsInitFile(keyword)) ResetName = keyword; else { cerr << "The argument \"" << keyword << "\" cannot be interpreted as a file name or option." << endl; exit(1); } } else //Unknown keyword so print the help file, the bad keyword and abort { PrintHelp(); cerr << "The argument \"" << keyword << "\" cannot be interpreted as a file name or option." << endl; exit(1); } } // Post-processing for script options. check for incompatible options. if (catalog && !ScriptName.empty()) { cerr << "Cannot specify catalog with script option" << endl << endl; result = false; } if (AircraftName.size() > 0 && ResetName.size() == 0 && !catalog) { cerr << "You must specify an initialization file with the aircraft name." << endl << endl; result = false; } if ((ScriptName.size() > 0 && AircraftName.size() > 0) || (ScriptName.size() > 0 && ResetName.size() > 0)) { cerr << "You cannot specify an aircraft or initialization file with a script." << endl; result = false; } return result; }