+static bool
+parse_colon (const string &s, double * val1, double * val2)
+{
+ string::size_type pos = s.find(':');
+ if (pos == string::npos) {
+ *val2 = atof(s);
+ return false;
+ } else {
+ *val1 = atof(s.substr(0, pos).c_str());
+ *val2 = atof(s.substr(pos+1).c_str());
+ return true;
+ }
+}
+
+
+static int
+fgOptFailure( const char * arg )
+{
+ string a = arg;
+ if (a == "pitot") {
+ fgSetBool("/systems/pitot/serviceable", false);
+ } else if (a == "static") {
+ fgSetBool("/systems/static/serviceable", false);
+ } else if (a == "vacuum") {
+ fgSetBool("/systems/vacuum/serviceable", false);
+ } else if (a == "electrical") {
+ fgSetBool("/systems/electrical/serviceable", false);
+ } else {
+ SG_LOG(SG_INPUT, SG_ALERT, "Unknown failure mode: " << a);
+ return FG_OPTIONS_ERROR;
+ }
+
+ return FG_OPTIONS_OK;
+}
+
+
+static int
+fgOptNAV1( const char * arg )
+{
+ double radial, freq;
+ if (parse_colon(arg, &radial, &freq))
+ fgSetDouble("/instrumentation/nav[0]/radials/selected-deg", radial);
+ fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", freq);
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptNAV2( const char * arg )
+{
+ double radial, freq;
+ if (parse_colon(arg, &radial, &freq))
+ fgSetDouble("/instrumentation/nav[1]/radials/selected-deg", radial);
+ fgSetDouble("/instrumentation/nav[1]/frequencies/selected-mhz", freq);
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptADF( const char * arg )
+{
+ double rot, freq;
+ if (parse_colon(arg, &rot, &freq))
+ fgSetDouble("/instrumentation/adf/rotation-deg", rot);
+ fgSetDouble("/instrumentation/adf/frequencies/selected-khz", freq);
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptDME( const char *arg )
+{
+ string opt = arg;
+ if (opt == "nav1") {
+ fgSetInt("/instrumentation/dme/switch-position", 1);
+ fgSetString("/instrumentation/dme/frequencies/source",
+ "/instrumentation/nav[0]/frequencies/selected-mhz");
+ } else if (opt == "nav2") {
+ fgSetInt("/instrumentation/dme/switch-position", 3);
+ fgSetString("/instrumentation/dme/frequencies/source",
+ "/instrumentation/nav[1]/frequencies/selected-mhz");
+ } else {
+ fgSetInt("/instrumentation/dme/switch-position", 2);
+ fgSetString("/instrumentation/dme/frequencies/source",
+ "/instrumentation/dme/frequencies/selected-mhz");
+ fgSetString("/instrumentation/dme/frequencies/selected-mhz", arg);
+ }
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptLivery( const char *arg )
+{
+ string opt = arg;
+ string livery_path = "livery/" + opt;
+ fgSetString("/sim/model/texture-path", livery_path.c_str() );
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptScenario( const char *arg )
+{
+ SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
+ vector<SGPropertyNode_ptr> scenarii = ai_node->getChildren( "scenario" );
+ int index = -1;
+ for ( size_t i = 0; i < scenarii.size(); ++i ) {
+ int ind = scenarii[i]->getIndex();
+ if ( index < ind ) {
+ index = ind;
+ }
+ }
+ SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
+ scenario->setStringValue( arg );
+ ai_node->setBoolValue( "enabled", true );
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptRunway( const char *arg )
+{
+ fgSetString("/sim/presets/runway", arg );
+ fgSetBool("/sim/presets/runway-requested", true );
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptParking( const char *arg )
+{
+ cerr << "Processing argument " << arg << endl;
+ fgSetString("/sim/presets/parking", arg );
+ fgSetBool ("/sim/presets/parking-requested", true );
+ return FG_OPTIONS_OK;
+}
+
+static int
+fgOptVersion( const char *arg )
+{
+ cerr << VERSION << endl;
+ cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
+ cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
+ return FG_OPTIONS_EXIT;
+}
+