]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Network updates contributed by Oliver Delise.
[flightgear.git] / src / Main / fg_init.cxx
index 149eebb780cd897189562efec1866ce66156367b..cecf5d65474d6431922898ed38e37b7b43f195f8 100644 (file)
@@ -62,6 +62,7 @@
 #include <Math/fg_geodesy.hxx>
 #include <Math/point3d.hxx>
 #include <Math/polar3d.hxx>
+#include <Misc/fgpath.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Time/event.hxx>
@@ -85,8 +86,40 @@ FG_USING_STD(string);
 extern const char *default_root;
 
 
+// Read in configuration (file and command line)
+bool fgInitConfig ( int argc, char **argv ) {
+    // Attempt to locate and parse a config file
+    // First check fg_root
+    FGPath config( current_options.get_fg_root() );
+    config.append( "system.fgfsrc" );
+    current_options.parse_config_file( config.str() );
+
+    // Next check home directory
+    char* envp = ::getenv( "HOME" );
+    if ( envp != NULL ) {
+       config.set( envp );
+       config.append( ".fgfsrc" );
+       current_options.parse_config_file( config.str() );
+    }
+
+    // Parse remaining command line options
+    // These will override anything specified in a config file
+    if ( current_options.parse_command_line(argc, argv) !=
+        fgOPTIONS::FG_OPTIONS_OK )
+    {
+       // Something must have gone horribly wrong with the command
+       // line parsing or maybe the user just requested help ... :-)
+       current_options.usage();
+       FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
+       return false;
+    }
+
+    return true;
+}
+
+
 // Set initial position and orientation
-int fgInitPosition( void ) {
+bool fgInitPosition( void ) {
     string id;
     FGInterface *f;
 
@@ -132,12 +165,12 @@ int fgInitPosition( void ) {
            << (f->get_Latitude() * RAD_TO_DEG) << ", "
            << (f->get_Altitude() * FEET_TO_METER) << ")" );
 
-    return(1);
+    return true;
 }
 
 
 // General house keeping initializations
-int fgInitGeneral( void ) {
+bool fgInitGeneral( void ) {
     string root;
     char *mesa_win_state;
 
@@ -169,7 +202,7 @@ int fgInitGeneral( void ) {
     }
 #endif
 
-    return 1;
+    return true;
 }
 
 
@@ -177,8 +210,7 @@ int fgInitGeneral( void ) {
 // initialization routines.  If you are adding a subsystem to flight
 // gear, its initialization call should located in this routine.
 // Returns non-zero if a problem encountered.
-int fgInitSubsystems( void )
-{
+bool fgInitSubsystems( void ) {
     FGTime::cur_time_params = new FGTime();
 
     FGInterface *f; // assigned later
@@ -422,7 +454,7 @@ int fgInitSubsystems( void )
 
     FG_LOG( FG_GENERAL, FG_INFO, endl);
 
-    return(1);
+    return true;
 }