1
0
Fork 0

Minor clean-up.

This commit is contained in:
ThorstenB 2012-04-21 09:38:41 +02:00
parent 3edd350c55
commit b358af2611
3 changed files with 14 additions and 28 deletions

View 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);
}

View 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

View 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