]> git.mxchange.org Git - flightgear.git/commitdiff
Minor clean-up.
authorThorstenB <brehmt@gmail.com>
Sat, 21 Apr 2012 07:38:41 +0000 (09:38 +0200)
committerThorstenB <brehmt@gmail.com>
Sat, 21 Apr 2012 17:06:10 +0000 (19:06 +0200)
src/Main/bootstrap.cxx
src/Main/main.hxx
src/Main/options.cxx

index 0b648fc590945c115873288a9d97c5a1cd3794af..a5d5c2a47f8640f027144da4f139336316132397 100644 (file)
@@ -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);
 }
 
index 115b3c628f8a9df9a38f90c86339db9df65ad6df..b6c2d3442a34c896a672148f52ae0066b1868d89 100644 (file)
@@ -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
index f40d2a7c0257dd2abe13df3ec68d790fc687bb17..4ed3f3252f91b40ad1e79a8d1a57357198d4f233 100644 (file)
@@ -58,6 +58,7 @@
 #include "options.hxx"
 #include "util.hxx"
 #include "viewmgr.hxx"
+#include "main.hxx"
 #include <Main/viewer.hxx>
 #include <Environment/presets.hxx>
 
@@ -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