}
+static string fgFindAircraftPath( const SGPath &path, const string &aircraft ) {
+ ulDirEnt* dire;
+ ulDir *dirp = ulOpenDir(path.str().c_str());
+ if (dirp == NULL) {
+ cerr << "Unable to open aircraft directory." << endl;
+ exit(-1);
+ }
+
+ while ((dire = ulReadDir(dirp)) != NULL) {
+ if (dire->d_isdir) {
+ if ( strcmp("CVS", dire->d_name) && strcmp(".", dire->d_name)
+ && strcmp("..", dire->d_name) )
+ {
+ SGPath next = path;
+ next.append(dire->d_name);
+
+ string result = fgFindAircraftPath( next, aircraft );
+ if ( ! result.empty() ) {
+ return result;
+ }
+ }
+ } else if ( !strcmp(dire->d_name, aircraft.c_str()) ) {
+ return path.str();
+ }
+ }
+
+ ulCloseDir(dirp);
+
+ return "";
+}
+
+
// Read in configuration (file and command line)
bool fgInitConfig ( int argc, char **argv ) {
// Scan user config files and command line for a specified aircraft.
fgInitFGAircraft(argc, argv);
- string aircraft = fgGetString("/sim/aircraft", "");
+ 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");
-
- if ( !ulFileExists(aircraft_path.c_str()) ) {
- string adir = aircraft;
- int pos, alen = adir.length();
-
- if ( ((pos = adir.rfind("-jsbsim")) != string::npos) ||
- ((pos = adir.rfind("-yasim")) != string::npos) ||
- ((pos = adir.rfind("-uiuc")) != string::npos) )
- {
- adir.erase(pos, alen);
+ SGPath aircraft_search( globals->get_fg_root() );
+ aircraft_search.append( "Aircraft" );
+
+ string aircraft_set = aircraft + "-set.xml";
+
+ string result = fgFindAircraftPath( aircraft_search, aircraft_set );
+ if ( !result.empty() ) {
+ SGPath full_name( result );
+ full_name.append( aircraft_set );
+
+ SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
+ << " from " << full_name.str());
+ try {
+ readProperties( full_name.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);
}
-
- aircraft_path = globals->get_fg_root();
- aircraft_path.append("Aircraft");
- aircraft_path.append(adir);
- 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, "Cannot find specified aircraft: "
+ << aircraft );
}
+
} else {
- SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
+ SG_LOG( SG_INPUT, SG_ALERT, "No default aircraft specified" );
}
// parse options after loading aircraft to ensure any user
else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
SGPath path( globals->get_fg_root() );
path.append("Aircraft");
- fgShowAircraft(path);
+ fgShowAircraft(path, true);
exit(0);
}
}
}
}
-/*
- * Search in the current directory, and in on directory deeper
- * for <aircraft>-set.xml configuration files and show the aircaft name
- * and the contents of the<description> tag in a sorted manner.
- *
- * @parampath the directory to search for configuration files
- * @param recursive defines whether the directory should be searched recursively
- */
-void fgShowAircraft(const SGPath &path, bool recursive) {
- static vector<string> aircraft;
-
+static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
+ bool recursive)
+{
ulDirEnt* dire;
ulDir *dirp = ulOpenDir(path.str().c_str());
if (dirp == NULL) {
SGPath next = path;
next.append(dire->d_name);
- fgShowAircraft(next, false);
+ fgSearchAircraft(next, aircraft, true);
}
} else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
}
}
- if (recursive) {
- sort(aircraft.begin(), aircraft.end());
- cout << "Available aircraft:" << endl;
- for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
- cout << aircraft[i] << endl;
- }
+ ulCloseDir(dirp);
+}
+
+
+/*
+ * Search in the current directory, and in on directory deeper
+ * for <aircraft>-set.xml configuration files and show the aircaft name
+ * and the contents of the<description> tag in a sorted manner.
+ *
+ * @parampath the directory to search for configuration files
+ * @param recursive defines whether the directory should be searched recursively
+ */
+void fgShowAircraft(const SGPath &path, bool recursive) {
+ string_list aircraft;
+
+ fgSearchAircraft( path, aircraft, recursive );
- aircraft.clear();
+ sort(aircraft.begin(), aircraft.end());
+ cout << "Available aircraft:" << endl;
+ for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
+ cout << aircraft[i] << endl;
}
- ulCloseDir(dirp);
}