From 76cda01641d3176fa1de985be84fdc3462f1b248 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 10 Oct 2002 18:39:52 +0000 Subject: [PATCH] Fixed init-order bug that caused c172-set.xml defaults always to be used unless explicitly overwritten. Now, the options are parsed twice, and only the *-set.xml file for the *last* aircraft specified is loaded. --- src/Main/fg_init.cxx | 78 ++++++++++++++++++++++++-------------------- src/Main/options.cxx | 9 +---- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 8314d7bbd..65c52b1e3 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -341,6 +341,46 @@ bool fgDetectLanguage() { return true; } +// Attempt to locate and parse the various non-XML config files in order +// from least precidence to greatest precidence +static void +do_options (int argc, char ** argv) +{ + // Check for $fg_root/system.fgfsrc + SGPath config( globals->get_fg_root() ); + config.append( "system.fgfsrc" ); + fgParseOptions(config.str()); + +#if defined( unix ) || defined( __CYGWIN__ ) + char name[256]; + // Check for $fg_root/system.fgfsrc.hostname + gethostname( name, 256 ); + config.concat( "." ); + config.concat( name ); + fgParseOptions(config.str()); +#endif + + // Check for ~/.fgfsrc + char* envp = ::getenv( "HOME" ); + if ( envp != NULL ) { + config.set( envp ); + config.append( ".fgfsrc" ); + fgParseOptions(config.str()); + } + +#if defined( unix ) || defined( __CYGWIN__ ) + // Check for ~/.fgfsrc.hostname + gethostname( name, 256 ); + config.concat( "." ); + config.concat( name ); + fgParseOptions(config.str()); +#endif + + // Parse remaining command line options + // These will override anything specified in a config file + fgParseArgs(argc, argv); +} + // Read in configuration (file and command line) bool fgInitConfig ( int argc, char **argv ) { @@ -360,6 +400,7 @@ bool fgInitConfig ( int argc, char **argv ) { return false; // Read the default aircraft config file. + do_options(argc, argv); // preparse options for default aircraft string aircraft = fgGetString("/sim/aircraft", ""); if (aircraft.size() > 0) { SGPath aircraft_path(globals->get_fg_root()); @@ -380,42 +421,7 @@ bool fgInitConfig ( int argc, char **argv ) { SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified"); } - // Attempt to locate and parse the various config files in order - // from least precidence to greatest precidence - - // Check for $fg_root/system.fgfsrc - SGPath config( globals->get_fg_root() ); - config.append( "system.fgfsrc" ); - fgParseOptions(config.str()); - -#if defined( unix ) || defined( __CYGWIN__ ) - char name[256]; - // Check for $fg_root/system.fgfsrc.hostname - gethostname( name, 256 ); - config.concat( "." ); - config.concat( name ); - fgParseOptions(config.str()); -#endif - - // Check for ~/.fgfsrc - char* envp = ::getenv( "HOME" ); - if ( envp != NULL ) { - config.set( envp ); - config.append( ".fgfsrc" ); - fgParseOptions(config.str()); - } - -#if defined( unix ) || defined( __CYGWIN__ ) - // Check for ~/.fgfsrc.hostname - gethostname( name, 256 ); - config.concat( "." ); - config.concat( name ); - fgParseOptions(config.str()); -#endif - - // Parse remaining command line options - // These will override anything specified in a config file - fgParseArgs(argc, argv); + do_options(argc, argv); return true; } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 9dd26a912..abbbcd1d4 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -989,14 +989,7 @@ parse_option (const string& arg) exit(2); } } else if ( arg.find( "--aircraft=" ) == 0 ) { - // read in the top level aircraft definition file - SGPath apath( globals->get_fg_root() ); - apath.append( "Aircraft" ); - apath.append( arg.substr(11) ); - apath.concat( "-set.xml" ); - SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11) - << " from " << apath.str()); - readProperties( apath.str(), globals->get_props() ); + fgSetString("/sim/aircraft", arg.substr(11).c_str()); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" ); return FG_OPTIONS_ERROR; -- 2.39.5