Get the environment variables HOME and HOSTNAME only once.
This commit is contained in:
parent
e0db27eb6f
commit
49ba607726
3 changed files with 47 additions and 39 deletions
|
@ -56,6 +56,10 @@ SG_USING_STD(endl);
|
||||||
# include <console.h> // -dw- for command line dialog
|
# include <console.h> // -dw- for command line dialog
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *homedir = ::getenv( "HOME" );
|
||||||
|
char *hostname = ::getenv( "HOSTNAME" );
|
||||||
|
bool free_hostname = false;
|
||||||
|
|
||||||
// foreward declaration.
|
// foreward declaration.
|
||||||
void fgExitCleanup();
|
void fgExitCleanup();
|
||||||
|
|
||||||
|
@ -215,5 +219,8 @@ void fgExitCleanup() {
|
||||||
fgSetMouseCursor(MOUSE_CURSOR_POINTER);
|
fgSetMouseCursor(MOUSE_CURSOR_POINTER);
|
||||||
|
|
||||||
delete globals;
|
delete globals;
|
||||||
|
|
||||||
|
if (free_hostname && hostname != NULL)
|
||||||
|
free(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,7 @@
|
||||||
#include "globals.hxx"
|
#include "globals.hxx"
|
||||||
#include "logger.hxx"
|
#include "logger.hxx"
|
||||||
#include "viewmgr.hxx"
|
#include "viewmgr.hxx"
|
||||||
|
#include "main.hxx"
|
||||||
|
|
||||||
#if defined(FX) && defined(XMESA)
|
#if defined(FX) && defined(XMESA)
|
||||||
#include <GL/xmesa.h>
|
#include <GL/xmesa.h>
|
||||||
|
@ -211,23 +212,27 @@ static string fgScanForOption( const string& option, const string& path ) {
|
||||||
// fg_root
|
// fg_root
|
||||||
bool fgInitFGRoot ( int argc, char **argv ) {
|
bool fgInitFGRoot ( int argc, char **argv ) {
|
||||||
string root;
|
string root;
|
||||||
char* envp;
|
|
||||||
|
|
||||||
// First parse command line options looking for --fg-root=, this
|
// First parse command line options looking for --fg-root=, this
|
||||||
// will override anything specified in a config file
|
// will override anything specified in a config file
|
||||||
root = fgScanForOption( "--fg-root=", argc, argv);
|
root = fgScanForOption( "--fg-root=", argc, argv);
|
||||||
|
|
||||||
|
if (hostname == NULL)
|
||||||
|
{
|
||||||
|
char _hostname[256];
|
||||||
|
gethostname(_hostname, 256);
|
||||||
|
hostname = strdup(_hostname);
|
||||||
|
free_hostname = true;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined( unix ) || defined( __CYGWIN__ )
|
#if defined( unix ) || defined( __CYGWIN__ )
|
||||||
// Next check home directory for .fgfsrc.hostname file
|
// Next check home directory for .fgfsrc.hostname file
|
||||||
if ( root.empty() ) {
|
if ( root.empty() ) {
|
||||||
envp = ::getenv( "HOME" );
|
if ( homedir != NULL ) {
|
||||||
if ( envp != NULL ) {
|
SGPath config( homedir );
|
||||||
SGPath config( envp );
|
|
||||||
config.append( ".fgfsrc" );
|
config.append( ".fgfsrc" );
|
||||||
char name[256];
|
|
||||||
gethostname( name, 256 );
|
|
||||||
config.concat( "." );
|
config.concat( "." );
|
||||||
config.concat( name );
|
config.concat( hostname );
|
||||||
root = fgScanForOption( "--fg-root=", config.str() );
|
root = fgScanForOption( "--fg-root=", config.str() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,9 +240,8 @@ bool fgInitFGRoot ( int argc, char **argv ) {
|
||||||
|
|
||||||
// Next check home directory for .fgfsrc file
|
// Next check home directory for .fgfsrc file
|
||||||
if ( root.empty() ) {
|
if ( root.empty() ) {
|
||||||
envp = ::getenv( "HOME" );
|
if ( homedir != NULL ) {
|
||||||
if ( envp != NULL ) {
|
SGPath config( homedir );
|
||||||
SGPath config( envp );
|
|
||||||
config.append( ".fgfsrc" );
|
config.append( ".fgfsrc" );
|
||||||
root = fgScanForOption( "--fg-root=", config.str() );
|
root = fgScanForOption( "--fg-root=", config.str() );
|
||||||
}
|
}
|
||||||
|
@ -245,7 +249,7 @@ bool fgInitFGRoot ( int argc, char **argv ) {
|
||||||
|
|
||||||
// Next check if fg-root is set as an env variable
|
// Next check if fg-root is set as an env variable
|
||||||
if ( root.empty() ) {
|
if ( root.empty() ) {
|
||||||
envp = ::getenv( "FG_ROOT" );
|
char *envp = ::getenv( "FG_ROOT" );
|
||||||
if ( envp != NULL ) {
|
if ( envp != NULL ) {
|
||||||
root = envp;
|
root = envp;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +299,7 @@ bool fgInitFGRoot ( int argc, char **argv ) {
|
||||||
// aircraft
|
// aircraft
|
||||||
bool fgInitFGAircraft ( int argc, char **argv ) {
|
bool fgInitFGAircraft ( int argc, char **argv ) {
|
||||||
string aircraft;
|
string aircraft;
|
||||||
char* envp;
|
char* homedir;
|
||||||
|
|
||||||
// First parse command line options looking for --aircraft=, this
|
// First parse command line options looking for --aircraft=, this
|
||||||
// will override anything specified in a config file
|
// will override anything specified in a config file
|
||||||
|
@ -304,14 +308,11 @@ bool fgInitFGAircraft ( int argc, char **argv ) {
|
||||||
#if defined( unix ) || defined( __CYGWIN__ )
|
#if defined( unix ) || defined( __CYGWIN__ )
|
||||||
// Next check home directory for .fgfsrc.hostname file
|
// Next check home directory for .fgfsrc.hostname file
|
||||||
if ( aircraft.empty() ) {
|
if ( aircraft.empty() ) {
|
||||||
envp = ::getenv( "HOME" );
|
if ( homedir != NULL ) {
|
||||||
if ( envp != NULL ) {
|
SGPath config( homedir );
|
||||||
SGPath config( envp );
|
|
||||||
config.append( ".fgfsrc" );
|
config.append( ".fgfsrc" );
|
||||||
char name[256];
|
|
||||||
gethostname( name, 256 );
|
|
||||||
config.concat( "." );
|
config.concat( "." );
|
||||||
config.concat( name );
|
config.concat( hostname );
|
||||||
aircraft = fgScanForOption( "--aircraft=", config.str() );
|
aircraft = fgScanForOption( "--aircraft=", config.str() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,9 +320,8 @@ bool fgInitFGAircraft ( int argc, char **argv ) {
|
||||||
|
|
||||||
// Next check home directory for .fgfsrc file
|
// Next check home directory for .fgfsrc file
|
||||||
if ( aircraft.empty() ) {
|
if ( aircraft.empty() ) {
|
||||||
envp = ::getenv( "HOME" );
|
if ( homedir != NULL ) {
|
||||||
if ( envp != NULL ) {
|
SGPath config( homedir );
|
||||||
SGPath config( envp );
|
|
||||||
config.append( ".fgfsrc" );
|
config.append( ".fgfsrc" );
|
||||||
aircraft = fgScanForOption( "--aircraft=", config.str() );
|
aircraft = fgScanForOption( "--aircraft=", config.str() );
|
||||||
}
|
}
|
||||||
|
@ -493,27 +493,22 @@ do_options (int argc, char ** argv)
|
||||||
fgParseOptions(config.str());
|
fgParseOptions(config.str());
|
||||||
|
|
||||||
#if defined( unix ) || defined( __CYGWIN__ )
|
#if defined( unix ) || defined( __CYGWIN__ )
|
||||||
char name[256];
|
|
||||||
// Check for $fg_root/system.fgfsrc.hostname
|
|
||||||
gethostname( name, 256 );
|
|
||||||
config.concat( "." );
|
config.concat( "." );
|
||||||
config.concat( name );
|
config.concat( hostname );
|
||||||
fgParseOptions(config.str());
|
fgParseOptions(config.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check for ~/.fgfsrc
|
// Check for ~/.fgfsrc
|
||||||
char* envp = ::getenv( "HOME" );
|
if ( homedir != NULL ) {
|
||||||
if ( envp != NULL ) {
|
config.set( homedir );
|
||||||
config.set( envp );
|
|
||||||
config.append( ".fgfsrc" );
|
config.append( ".fgfsrc" );
|
||||||
fgParseOptions(config.str());
|
fgParseOptions(config.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined( unix ) || defined( __CYGWIN__ )
|
#if defined( unix ) || defined( __CYGWIN__ )
|
||||||
// Check for ~/.fgfsrc.hostname
|
// Check for ~/.fgfsrc.hostname
|
||||||
gethostname( name, 256 );
|
|
||||||
config.concat( "." );
|
config.concat( "." );
|
||||||
config.concat( name );
|
config.concat( hostname );
|
||||||
fgParseOptions(config.str());
|
fgParseOptions(config.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -608,21 +603,23 @@ bool fgInitConfig ( int argc, char **argv ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
char* envp = ::getenv( "APPDATA" );
|
char *envp = ::getenv( "APPDATA" );
|
||||||
#else
|
if (envp != NULL ) {
|
||||||
char* envp = ::getenv( "HOME" );
|
SGPath config( env );
|
||||||
#endif
|
|
||||||
if ( envp != NULL ) {
|
|
||||||
SGPath config( globals->get_fg_root() );
|
|
||||||
config.set( envp );
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
config.append( "flightgear.org" );
|
config.append( "flightgear.org" );
|
||||||
#else
|
#else
|
||||||
|
if ( homedir != NULL ) {
|
||||||
|
SGPath config( homedir );
|
||||||
config.append( ".fgfs" );
|
config.append( ".fgfs" );
|
||||||
#endif
|
#endif
|
||||||
config.append( "preferences.xml" );
|
config.append( "preferences.xml" );
|
||||||
SG_LOG(SG_INPUT, SG_INFO, "Reading user preferences");
|
SG_LOG(SG_INPUT, SG_INFO, "Reading user preferences");
|
||||||
fgLoadProps(config.str().c_str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
|
try {
|
||||||
|
fgLoadProps(config.str().c_str(), globals->get_props(), false,
|
||||||
|
SGPropertyNode::USERARCHIVE);
|
||||||
|
} catch (...) {
|
||||||
|
SG_LOG(SG_INPUT, SG_BULK, "First time reading user preferences.");
|
||||||
|
}
|
||||||
SG_LOG(SG_INPUT, SG_BULK, "Finished Reading user preferences");
|
SG_LOG(SG_INPUT, SG_BULK, "Finished Reading user preferences");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,8 @@ extern int idle_state;
|
||||||
extern long global_multi_loop;
|
extern long global_multi_loop;
|
||||||
extern double delta_time_sec;
|
extern double delta_time_sec;
|
||||||
|
|
||||||
|
extern char *homedir;
|
||||||
|
extern char *hostname;
|
||||||
|
extern bool free_hostname;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue