From: ThorstenB Date: Sat, 21 Apr 2012 07:38:41 +0000 (+0200) Subject: Minor clean-up. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b358af2611191e8c49195159de42f61de6c95423;p=flightgear.git Minor clean-up. --- diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index 0b648fc59..a5d5c2a47 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -65,11 +65,10 @@ using std::endl; #include "fg_os.hxx" -char *homedir = NULL; -char *hostname = NULL; -bool free_hostname = false; +string homedir; +string hostname; -// foreward declaration. +// forward declaration. void fgExitCleanup(); static bool fpeAbort = false; @@ -175,21 +174,15 @@ int main ( int argc, char **argv ) { SetErrorMode(SEM_NOOPENFILEERRORBOX); // Windows has no $HOME aka %HOME%, so we have to construct the full path. - // make sure it fits into the buffer. Max. path length is 255, but who knows - // what's in these environment variables? - char homepath[256] = ""; - homepath[sizeof(homepath)-1] = 0; - strncpy( homepath, ::getenv("APPDATA"), sizeof(homepath)-1 ); - strncat( homepath, "\\flightgear.org", sizeof(homepath)-strlen(homepath)-1 ); - - homedir = strdup(homepath); + homedir = ::getenv("APPDATA"); + homedir.append("\\flightgear.org"); + hostname = ::getenv( "COMPUTERNAME" ); #else // Unix(alike) systems char _hostname[256]; gethostname(_hostname, 256); - hostname = strdup(_hostname); - free_hostname = true; + hostname = _hostname; homedir = ::getenv( "HOME" ); @@ -290,8 +283,5 @@ void fgExitCleanup() { fgSetMouseCursor(MOUSE_CURSOR_POINTER); delete globals; - - if (free_hostname && hostname != NULL) - free(hostname); } diff --git a/src/Main/main.hxx b/src/Main/main.hxx index 115b3c628..b6c2d3442 100644 --- a/src/Main/main.hxx +++ b/src/Main/main.hxx @@ -9,8 +9,7 @@ int fgMainInit( int argc, char **argv ); extern int idle_state; -extern char *homedir; -extern char *hostname; -extern bool free_hostname; +extern string homedir; +extern string hostname; #endif diff --git a/src/Main/options.cxx b/src/Main/options.cxx index f40d2a7c0..4ed3f3252 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -58,6 +58,7 @@ #include "options.hxx" #include "util.hxx" #include "viewmgr.hxx" +#include "main.hxx" #include
#include @@ -84,10 +85,6 @@ using std::cin; #define NEW_DEFAULT_MODEL_HZ 120 -// defined in bootstrap.cxx -extern char *homedir; -extern char *hostname; - enum { FG_OPTIONS_OK = 0, @@ -1738,7 +1735,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath) // then config files SGPath config; - if( homedir && hostname && strlen(hostname) > 0 ) { + if( homedir.size() && hostname.size() ) { // Check for ~/.fgfsrc.hostname config.set(homedir); config.append(".fgfsrc"); @@ -1748,7 +1745,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath) } // Check for ~/.fgfsrc - if( homedir ) { + if( homedir.size() ) { config.set(homedir); config.append(".fgfsrc"); readConfig(config); @@ -1765,7 +1762,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath) setupRoot(); // system.fgfsrc handling - if( hostname && strlen(hostname) > 0 ) { + if( hostname.size() > 0 ) { config.set(globals->get_fg_root()); config.append( "system.fgfsrc" ); config.concat( "." ); @@ -1971,7 +1968,7 @@ string_list Options::valuesForOption(const std::string& key) const return result; } - + void Options::processOptions() { // establish locale before showing help