X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Ffg_init.cxx;h=5ad9476021430d06c3222f18f74720a1bb372b36;hb=62c6063fa1cbe6256fd497d86e25be99bf1edfb0;hp=bfd8d23a18f00e4ed3118bc919f992f506557a7b;hpb=49ba607726ef285d242d3a62889204ccbe94c0cd;p=flightgear.git diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index bfd8d23a1..5ad947602 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -207,15 +207,10 @@ static string fgScanForOption( const string& option, const string& path ) { return ""; } - -// Read in configuration (files and command line options) but only set -// fg_root -bool fgInitFGRoot ( int argc, char **argv ) { - string root; - - // First parse command line options looking for --fg-root=, this - // will override anything specified in a config file - root = fgScanForOption( "--fg-root=", argc, argv); +// Scan the user config files for the specified option and return +// the value. +static string fgScanForOption( const string& option ) { + string arg(""); if (hostname == NULL) { @@ -227,25 +222,49 @@ bool fgInitFGRoot ( int argc, char **argv ) { #if defined( unix ) || defined( __CYGWIN__ ) // Next check home directory for .fgfsrc.hostname file - if ( root.empty() ) { + if ( arg.empty() ) { if ( homedir != NULL ) { SGPath config( homedir ); config.append( ".fgfsrc" ); config.concat( "." ); config.concat( hostname ); - root = fgScanForOption( "--fg-root=", config.str() ); + arg = fgScanForOption( option, config.str() ); } } #endif // Next check home directory for .fgfsrc file - if ( root.empty() ) { + if ( arg.empty() ) { if ( homedir != NULL ) { SGPath config( homedir ); config.append( ".fgfsrc" ); - root = fgScanForOption( "--fg-root=", config.str() ); + arg = fgScanForOption( option, config.str() ); } } + + if ( arg.empty() ) { + // Check for $fg_root/system.fgfsrc + SGPath config( globals->get_fg_root() ); + config.append( "system.fgfsrc" ); + arg = fgScanForOption( option, config.str() ); + } + + return arg; +} + + +// Read in configuration (files and command line options) but only set +// fg_root +bool fgInitFGRoot ( int argc, char **argv ) { + string root; + + // First parse command line options looking for --fg-root=, this + // will override anything specified in a config file + root = fgScanForOption( "--fg-root=", argc, argv); + + // Check in one of the user configuration files. + if (root.empty() ) + root = fgScanForOption( "--fg-root=" ); // Next check if fg-root is set as an env variable if ( root.empty() ) { @@ -299,40 +318,15 @@ bool fgInitFGRoot ( int argc, char **argv ) { // aircraft bool fgInitFGAircraft ( int argc, char **argv ) { string aircraft; - char* homedir; // First parse command line options looking for --aircraft=, this // will override anything specified in a config file aircraft = fgScanForOption( "--aircraft=", argc, argv ); -#if defined( unix ) || defined( __CYGWIN__ ) - // Next check home directory for .fgfsrc.hostname file - if ( aircraft.empty() ) { - if ( homedir != NULL ) { - SGPath config( homedir ); - config.append( ".fgfsrc" ); - config.concat( "." ); - config.concat( hostname ); - aircraft = fgScanForOption( "--aircraft=", config.str() ); - } - } -#endif - - // Next check home directory for .fgfsrc file - if ( aircraft.empty() ) { - if ( homedir != NULL ) { - SGPath config( homedir ); - config.append( ".fgfsrc" ); - aircraft = fgScanForOption( "--aircraft=", config.str() ); - } - } + // Check in one of the user configuration files. + if ( aircraft.empty() ) + aircraft = fgScanForOption( "--aircraft=" ); - if ( aircraft.empty() ) { - // Check for $fg_root/system.fgfsrc - SGPath sysconf( globals->get_fg_root() ); - sysconf.append( "system.fgfsrc" ); - aircraft = fgScanForOption( "--aircraft=", sysconf.str() ); - } // if an aircraft was specified, set the property name if ( !aircraft.empty() ) { SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft ); @@ -605,7 +599,7 @@ bool fgInitConfig ( int argc, char **argv ) { #ifdef _MSC_VER char *envp = ::getenv( "APPDATA" ); if (envp != NULL ) { - SGPath config( env ); + SGPath config( envp ); config.append( "flightgear.org" ); #else if ( homedir != NULL ) {