diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index d2e5bb305..a052cafc1 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -37,6 +37,11 @@ #include #include + +#if defined( unix ) || defined( __CYGWIN__ ) +# include // for gethostname() +#endif + // work around a stdc++ lib bug in some versions of linux, but doesn't // seem to hurt to have this here for all versions of Linux. #ifdef linux @@ -116,6 +121,22 @@ bool fgInitFGRoot ( int argc, char **argv ) { // override anything specified in a config file root = fgScanForRoot(argc, argv); +#if defined( unix ) || defined( __CYGWIN__ ) + // Next check home directory for .fgfsrc.hostname file + if ( root == "" ) { + envp = ::getenv( "HOME" ); + if ( envp != NULL ) { + FGPath config( envp ); + config.append( ".fgfsrc" ); + char name[256]; + gethostname( name, 256 ); + config.concat( "." ); + config.concat( name ); + root = fgScanForRoot(config.str()); + } + } +#endif + // Next check home directory for .fgfsrc file if ( root == "" ) { envp = ::getenv( "HOME" ); @@ -170,13 +191,24 @@ bool fgInitConfig ( int argc, char **argv ) { FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences"); } - // Attempt to locate and parse a config file - // First check fg_root + // Attempt to locate and parse the various config files in order + // from least precidence to greatest precidence + + // Check for $fg_root/system.fgfsrc FGPath config( globals->get_fg_root() ); config.append( "system.fgfsrc" ); fgParseOptions(config.str()); - // Next check home directory + char name[256]; +#if defined( unix ) || defined( __CYGWIN__ ) + // 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 ); @@ -184,6 +216,14 @@ bool fgInitConfig ( int argc, char **argv ) { 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 fgParseOptions(argc, argv); diff --git a/tests/Makefile.am b/tests/Makefile.am index cbb62fa1c..8c7ab1281 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = est-epsilon gl-info test-mktime test-up +bin_PROGRAMS = est-epsilon gl-info test-gethostname test-mktime test-up est_epsilon_SOURCES = est-epsilon.c est_epsilon_LDADD = $(base_LIBS) @@ -6,6 +6,9 @@ est_epsilon_LDADD = $(base_LIBS) gl_info_SOURCES = gl-info.c gl_info_LDADD = $(opengl_LIBS) +test_gethostname_SOURCES = test-gethostname.cxx +test_gethostname_LDADD = $(base_LIBS) + test_mktime_SOURCES = test-mktime.cxx test_mktime_LDADD = $(base_LIBS)