]> git.mxchange.org Git - flightgear.git/commitdiff
Add support for a --show-aircraft option. This displays a list of all
authorcurt <curt>
Wed, 28 Aug 2002 16:59:40 +0000 (16:59 +0000)
committercurt <curt>
Wed, 28 Aug 2002 16:59:40 +0000 (16:59 +0000)
available aircraft and a brief description if one is available.

src/Main/options.cxx
src/Main/options.hxx

index a6b53934c6db57e57028bc3697db8c03cd094d62..8fc107c3713dfa88e4db82c79c742d516520832f 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>
@@ -69,7 +71,8 @@ enum
     FG_OPTIONS_OK = 0,
     FG_OPTIONS_HELP = 1,
     FG_OPTIONS_ERROR = 2,
-    FG_OPTIONS_VERBOSE_HELP = 3
+    FG_OPTIONS_VERBOSE_HELP = 3,
+    FG_OPTIONS_SHOW_AIRCRAFT = 4
 };
 
 static double
@@ -745,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 ) {
@@ -1083,6 +1088,11 @@ fgParseArgs (int argc, char **argv)
 
             else if (result == FG_OPTIONS_VERBOSE_HELP)
               verbose = true;
+
+            else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
+               fgShowAircraft();
+               exit(0);
+            }
          }
        } else {
          in_options = false;
@@ -1244,3 +1254,54 @@ fgUsage (bool verbose)
         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")) ) {
+          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);
+}
index 7d6866dde12062bb84e0f2aeb58c1903084a28a9..a6f8f42af3eb6569eba25705c8bb7eac26c35d9f 100644 (file)
@@ -35,5 +35,6 @@ extern string fgScanForRoot (const string &file_path);
 extern void fgParseArgs (int argc, char ** argv);
 extern void fgParseOptions (const string &file_path);
 extern void fgUsage (bool verbose = false);
+extern void fgShowAircraft();
 
 #endif /* _OPTIONS_HXX */