}
-// Read in configuration (file and command line)
-bool fgInitConfig ( int argc, char **argv ) {
-
- // First, set some sane default values
- fgSetDefaults();
-
- // Read global preferences from $FG_ROOT/preferences.xml
- SGPath props_path(globals->get_fg_root());
- props_path.append("preferences.xml");
- SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
- readProperties(props_path.str(), globals->get_props());
- SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
-
- // Read the default aircraft config file.
- string aircraft = fgGetString("/sim/aircraft", "");
- if (aircraft.size() > 0) {
- SGPath aircraft_path(globals->get_fg_root());
- aircraft_path.append("Aircraft");
- aircraft_path.append(aircraft);
- aircraft_path.concat("-set.xml");
- SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
- << " from " << aircraft_path.str());
- try {
- readProperties(aircraft_path.str(), globals->get_props());
- } catch (const sg_exception &e) {
- string message = "Error reading default aircraft: ";
- message += e.getFormattedMessage();
- SG_LOG(SG_INPUT, SG_ALERT, message);
- exit(2);
- }
- } else {
- SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
- }
-
- // Attempt to locate and parse the various config files in order
- // from least precidence to greatest precidence
-
- // Check for $fg_root/system.fgfsrc
- SGPath config( globals->get_fg_root() );
- config.append( "system.fgfsrc" );
- fgParseOptions(config.str());
-
-#if defined( unix ) || defined( __CYGWIN__ )
- char name[256];
- // 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 );
- config.append( ".fgfsrc" );
- 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
- fgParseArgs(argc, argv);
-
- return true;
-}
-
// Initialize the localization
SGPropertyNode *fgInitLocale(const char *language) {
SGPropertyNode *c_node = NULL, *d_node = NULL;
// localization not defined
if (!intl)
return NULL;
-
+
//
// Select the proper language from the list
//
return NULL;
}
-
//
// Load the language specific strings
//
}
+
+// Initialize the localization routines
+bool fgDetectLanguage() {
+ char *language = ::getenv("LANG");
+
+ if (language == NULL) {
+ SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
+ language = "C";
+ }
+
+ SGPropertyNode *locale = fgInitLocale(language);
+ if (!locale) {
+ cerr << "No internationalization settings specified in preferences.xml"
+ << endl;
+
+ return false;
+ }
+
+ globals->set_locale( locale );
+
+ return true;
+}
+
+
+// Read in configuration (file and command line)
+bool fgInitConfig ( int argc, char **argv ) {
+
+ // First, set some sane default values
+ fgSetDefaults();
+
+ // Read global preferences from $FG_ROOT/preferences.xml
+ SGPath props_path(globals->get_fg_root());
+ props_path.append("preferences.xml");
+ SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
+ readProperties(props_path.str(), globals->get_props());
+ SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
+
+ // Detect the required language as early as possible
+ if (fgDetectLanguage() != true)
+ return false;
+
+ // Read the default aircraft config file.
+ string aircraft = fgGetString("/sim/aircraft", "");
+ if (aircraft.size() > 0) {
+ SGPath aircraft_path(globals->get_fg_root());
+ aircraft_path.append("Aircraft");
+ aircraft_path.append(aircraft);
+ aircraft_path.concat("-set.xml");
+ SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
+ << " from " << aircraft_path.str());
+ try {
+ readProperties(aircraft_path.str(), globals->get_props());
+ } catch (const sg_exception &e) {
+ string message = "Error reading default aircraft: ";
+ message += e.getFormattedMessage();
+ SG_LOG(SG_INPUT, SG_ALERT, message);
+ exit(2);
+ }
+ } else {
+ SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
+ }
+
+ // Attempt to locate and parse the various config files in order
+ // from least precidence to greatest precidence
+
+ // Check for $fg_root/system.fgfsrc
+ SGPath config( globals->get_fg_root() );
+ config.append( "system.fgfsrc" );
+ fgParseOptions(config.str());
+
+#if defined( unix ) || defined( __CYGWIN__ )
+ char name[256];
+ // 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 );
+ config.append( ".fgfsrc" );
+ 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
+ fgParseArgs(argc, argv);
+
+ return true;
+}
+
+
// find basic airport location info from airport database
bool fgFindAirportID( const string& id, FGAirport *a ) {
if ( id.length() ) {
// sleep(1);
idle_state = 1000;
- cout << "Panel visible = " << fgPanelVisible() << endl;
+ SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
fgReshape( fgGetInt("/sim/startup/xsize"),
fgGetInt("/sim/startup/ysize") );
}
string base_version = fgBasePackageVersion();
if ( !(base_version == required_version) ) {
// tell the operator how to use this application
- fgUsage();
- cout << endl << "Base package check failed ... " \
+ cerr << endl << "Base package check failed ... " \
<< "Found version " << base_version << " at: " \
<< globals->get_fg_root() << endl;
- cout << "Please upgrade to version" << required_version << endl;
+ cerr << "Please upgrade to version" << required_version << endl;
exit(-1);
}
exit(-1);
}
- // Initialize the localization routines
- if (globals->get_locale() == NULL) {
- char *language = getenv("LANG");
- if (language == NULL) {
- SG_LOG(SG_GENERAL, SG_ALERT, "Unable to detect the language" );
- language = "C";
- }
-
- SGPropertyNode *locale = fgInitLocale(language);
- if (!locale) {
- cerr
- << "Not internationalization settings specified in preferences.xml"
- << endl;
-
- return false;
- }
-
- globals->set_locale( locale );
- }
-
// Initialize the Window/Graphics environment.
if( !fgGlutInit(&argc, argv) ) {
SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
void
fgUsage (bool verbose)
{
+ SGPropertyNode *locale = globals->get_locale();
+
SGPropertyNode options_root;
SGPath opath( globals->get_fg_root() );
opath.append( "options.xml" );
exit(-1);
}
- SGPropertyNode *usage = options->getNode("usage");
+ SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
if (usage) {
cout << "Usage: " << usage->getStringValue() << endl;
}
snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' ');
}
+ // There may be more than one <description> tag assosiated
+ // with one option
+
msg += cstr;
- SGPropertyNode *desc = option[k]->getNode("description");
- if (desc) {
- msg += desc->getStringValue();
-
- for ( unsigned int l = 1;
- (desc = option[k]->getNode("description", l, false));
- l++ )
- {
- snprintf(cstr, 96, "\n%32c%s", ' ',
- desc->getStringValue());
- msg += cstr;
- }
- msg += '\n';
- }
+ vector<SGPropertyNode_ptr>desc =
+ option[k]->getChildren("description");
+
+ if (desc.size() > 0) {
+ for ( unsigned int l = 0; l < desc.size(); l++) {
+
+ // There may be more than one translation line.
+
+ string t = desc[l]->getStringValue();
+ SGPropertyNode *n = locale->getNode("strings");
+ vector<SGPropertyNode_ptr>trans_desc =
+ n->getChildren(t.substr(8).c_str());
+
+ for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
+ string t_str = trans_desc[m]->getStringValue();
+
+ if ((m > 0) || ((l > 0) && m == 0)) {
+ snprintf(cstr, 96, "%32c", ' ');
+ msg += cstr;
+
+ }
+
+ // If the string is too large to fit on the screen,
+ // then split it up in several pieces.
+
+ while ( t_str.size() > 47 ) {
+
+ unsigned int m = t_str.rfind(' ', 47);
+ msg += t_str.substr(0, m);
+ snprintf(cstr, 96, "\n%32c", ' ');
+ msg += cstr;
+
+ t_str.erase(t_str.begin(), t_str.begin() + m + 1);
+ }
+ msg += t_str + '\n';
+ }
+ }
+ }
}
}
- SGPropertyNode *name = section[j]->getNode("name");
+ SGPropertyNode *name =
+ locale->getNode(section[j]->getStringValue("name"));
+
if (!msg.empty() && name) {
cout << endl << name->getStringValue() << ":" << endl;
cout << msg;