]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.cxx
Added static port system and a new altimeter model connected to it.
[flightgear.git] / src / Main / options.cxx
index 5f37bfcc8f6165ec3b7a6dac4525d057d1c27ec7..79c2ee290aa044ddbc0ebe5ffdfbc3f3e5632ad2 100644 (file)
@@ -35,6 +35,8 @@
 
 #include STL_STRING
 
+#include <plib/ul.h>
+
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/misc/sg_path.hxx>
@@ -68,7 +70,9 @@ enum
 {
     FG_OPTIONS_OK = 0,
     FG_OPTIONS_HELP = 1,
-    FG_OPTIONS_ERROR = 2
+    FG_OPTIONS_ERROR = 2,
+    FG_OPTIONS_VERBOSE_HELP = 3,
+    FG_OPTIONS_SHOW_AIRCRAFT = 4
 };
 
 static double
@@ -594,6 +598,9 @@ parse_option (const string& arg)
     if ( (arg == "--help") || (arg == "-h") ) {
        // help/usage request
        return(FG_OPTIONS_HELP);
+    } else if ( (arg == "--verbose") || (arg == "-v") ) {
+        // verbose help/usage request
+        return(FG_OPTIONS_VERBOSE_HELP);
     } else if ( arg == "--disable-game-mode") {
        fgSetBool("/sim/startup/game-mode", false);
     } else if ( arg == "--enable-game-mode" ) {
@@ -741,6 +748,8 @@ parse_option (const string& arg)
        fgSetString("/sim/aero", arg.substr(7).c_str());
     } else if ( arg.find( "--aircraft-dir=" ) == 0 ) {
         fgSetString("/sim/aircraft-dir", arg.substr(15).c_str());
+    } else if ( arg.find( "--show-aircraft") == 0) {
+        return(FG_OPTIONS_SHOW_AIRCRAFT);
     } else if ( arg.find( "--model-hz=" ) == 0 ) {
        fgSetInt("/sim/model-hz", atoi(arg.substr(11)));
     } else if ( arg.find( "--speed=" ) == 0 ) {
@@ -763,6 +772,10 @@ parse_option (const string& arg)
         fgSetBool("/environment/clouds/status", false);
     } else if ( arg == "--enable-clouds" ) {
         fgSetBool("/environment/clouds/status", true);
+    } else if ( arg == "--disable-clouds3d" ) {
+        fgSetBool("/sim/rendering/clouds3d", false);
+    } else if ( arg == "--enable-clouds3d" ) {
+        fgSetBool("/sim/rendering/clouds3d", true);
     } else if ( arg.find( "--fov=" ) == 0 ) {
        parse_fov( arg.substr(6) );
     } else if ( arg == "--disable-fullscreen" ) {
@@ -1061,6 +1074,8 @@ void
 fgParseArgs (int argc, char **argv)
 {
     bool in_options = true;
+    bool verbose = false;
+    bool help = false;
 
     SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments");
 
@@ -1072,11 +1087,16 @@ fgParseArgs (int argc, char **argv)
            in_options = false;
          } else {
            int result = parse_option(arg);
-           if ( (result == FG_OPTIONS_HELP) ||
-                (result == FG_OPTIONS_ERROR) ) {
-             fgUsage();
-             exit(-1);
-           }
+           if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR))
+              help = true;
+
+            else if (result == FG_OPTIONS_VERBOSE_HELP)
+              verbose = true;
+
+            else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
+               fgShowAircraft();
+               exit(0);
+            }
          }
        } else {
          in_options = false;
@@ -1086,6 +1106,11 @@ fgParseArgs (int argc, char **argv)
        }
     }
 
+    if (help) {
+       fgUsage(verbose);
+       exit(0);
+    }
+
     SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments");
 }
 
@@ -1122,9 +1147,8 @@ fgParseOptions (const string& path) {
         }
 
        if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
-           SG_LOG( SG_GENERAL, SG_ALERT, 
-                   "Config file parse error: " << path << " '" 
-                   << line << "'" );
+            cout << endl << "Config file parse error: " << path << " '" 
+                   << line << "'" << endl;
            fgUsage();
            exit(-1);
        }
@@ -1135,7 +1159,7 @@ fgParseOptions (const string& path) {
 
 // Print usage message
 void 
-fgUsage ()
+fgUsage (bool verbose)
 {
     SGPropertyNode options_root;
     SGPath opath( globals->get_fg_root() );
@@ -1148,7 +1172,7 @@ fgUsage ()
     } catch (const sg_exception &ex) {
         cout << "Unable to read the help file." << endl;
         cout << "Make sure the file options.xml is located in the FlightGear base directory," << endl;
-        cout << "and the location of the base directory is specified bij setting $FG_ROOT or" << endl;
+        cout << "and the location of the base directory is specified by setting $FG_ROOT or" << endl;
         cout << "by adding --fg-root=path as a program argument." << endl;
         
         exit(-1);
@@ -1168,11 +1192,7 @@ fgUsage ()
 
     vector<SGPropertyNode_ptr>section = options->getChildren("section");
     for (unsigned int j = 0; j < section.size(); j++) {
-
-        SGPropertyNode *name = section[j]->getNode("name");
-        if (name) {
-            cout << endl << name->getStringValue() << ":" << endl;
-        }
+        string msg = "";
 
         vector<SGPropertyNode_ptr>option = section[j]->getChildren("option");
         for (unsigned int k = 0; k < option.size(); k++) {
@@ -1181,8 +1201,9 @@ fgUsage ()
             SGPropertyNode *short_name = option[k]->getNode("short");
             SGPropertyNode *key = option[k]->getNode("key");
             SGPropertyNode *arg = option[k]->getNode("arg");
+            bool brief = option[k]->getNode("brief");
 
-            if (name) {
+            if ((brief || verbose) && name) {
                 string tmp = name->getStringValue();
 
                 if (key){
@@ -1204,8 +1225,8 @@ fgUsage ()
                 } else {
                     snprintf(cstr, 96, "\n   --%s\n%32c", tmp.c_str(), ' ');
                 }
-                string msg = cstr;
 
+                msg += cstr;
                 SGPropertyNode *desc = option[k]->getNode("description");
                 if (desc) {
                     msg += desc->getStringValue();
@@ -1218,9 +1239,72 @@ fgUsage ()
                                  desc->getStringValue());
                         msg += cstr;
                     }
+                    msg += '\n';
                 }
-                cout << msg << endl;
             }
         }
+
+        SGPropertyNode *name = section[j]->getNode("name");
+        if (!msg.empty() && name) {
+           cout << endl << name->getStringValue() << ":" << endl;
+           cout << msg;
+           msg.erase();
+        }
+    }
+
+    if ( !verbose ) {
+        cout << endl;
+        cout << "For a complete list of options use --help --verbose" << endl;
     }
 }
+
+// Show available aircraft types
+void fgShowAircraft(void) {
+   SGPath path( globals->get_fg_root() );
+   path.append("Aircraft");
+
+   ulDirEnt* dire;
+   ulDir *dirp;
+
+   dirp = ulOpenDir(path.c_str());
+   if (dirp == NULL) {
+      cout << "Unable to open aircraft directory." << endl;
+      exit(-1);
+   }
+
+   cout << "Available aircraft:" << endl;
+   while ((dire = ulReadDir(dirp)) != NULL) {
+      char *ptr;
+
+      if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) {
+          SGPath afile = path;
+          afile.append(dire->d_name);
+
+          *ptr = '\0';
+
+          SGPropertyNode root;
+          try {
+             readProperties(afile.str(), &root);
+          } catch (...) {
+             continue;
+          }
+
+          SGPropertyNode *desc, *node = root.getNode("sim");
+          if (node)
+             desc = node->getNode("description");
+
+          char cstr[96];
+          if (strlen(dire->d_name) <= 27)
+             snprintf(cstr, 96, "   %-27s  %s", dire->d_name,
+                      (desc) ? desc->getStringValue() : "" );
+
+          else
+             snprintf(cstr, 96, "   %-27s\n%32c%s", dire->d_name, ' ',
+                      (desc) ? desc->getStringValue() : "" );
+
+          cout << cstr << endl;
+      }
+   }
+
+   ulCloseDir(dirp);
+}