1
0
Fork 0

Add support for <aircraft>-set.xml configuration files inside it's own subdirectory. This applies only to the --show-aircraft option for now.

This commit is contained in:
ehofman 2003-09-15 14:07:50 +00:00
parent 7249aaea33
commit b7e3f95300
2 changed files with 38 additions and 21 deletions

View file

@ -1518,7 +1518,9 @@ fgParseArgs (int argc, char **argv)
verbose = true; verbose = true;
else if (result == FG_OPTIONS_SHOW_AIRCRAFT) { else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
fgShowAircraft(); SGPath path( globals->get_fg_root() );
path.append("Aircraft");
fgShowAircraft(path);
exit(0); exit(0);
} }
} }
@ -1711,17 +1713,19 @@ fgUsage (bool verbose)
} }
} }
// Show available aircraft types /*
void fgShowAircraft(void) { * Search in the current directory, and in on directory deeper
vector<string> aircraft; * for <aircraft>-set.xml configuration files and show the aircaft name
* and the contents of the<description> tag in a sorted manner.
SGPath path( globals->get_fg_root() ); *
path.append("Aircraft"); * @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;
ulDirEnt* dire; ulDirEnt* dire;
ulDir *dirp; ulDir *dirp = ulOpenDir(path.str().c_str());
dirp = ulOpenDir(path.c_str());
if (dirp == NULL) { if (dirp == NULL) {
cerr << "Unable to open aircraft directory." << endl; cerr << "Unable to open aircraft directory." << endl;
exit(-1); exit(-1);
@ -1730,7 +1734,17 @@ void fgShowAircraft(void) {
while ((dire = ulReadDir(dirp)) != NULL) { while ((dire = ulReadDir(dirp)) != NULL) {
char *ptr; char *ptr;
if ((ptr = strstr(dire->d_name, "-set.xml")) && ptr[8] == '\0' ) { if (dire->d_isdir) {
if (recursive && strcmp("CVS", dire->d_name)
&& strcmp(".", dire->d_name) && strcmp("..", dire->d_name))
{
SGPath next = path;
next.append(dire->d_name);
fgShowAircraft(next, false);
}
} else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
SGPath afile = path; SGPath afile = path;
afile.append(dire->d_name); afile.append(dire->d_name);
@ -1750,24 +1764,27 @@ void fgShowAircraft(void) {
} }
char cstr[96]; char cstr[96];
if (strlen(dire->d_name) <= 27) if (strlen(dire->d_name) <= 27) {
snprintf(cstr, 96, " %-27s %s", dire->d_name, snprintf(cstr, 96, " %-27s %s", dire->d_name,
(desc) ? desc->getStringValue() : "" ); (desc) ? desc->getStringValue() : "" );
else } else {
snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ', snprintf(cstr, 96, " %-27s\n%32c%s", dire->d_name, ' ',
(desc) ? desc->getStringValue() : "" ); (desc) ? desc->getStringValue() : "" );
}
aircraft.push_back(cstr); aircraft.push_back(cstr);
} }
} }
sort(aircraft.begin(), aircraft.end()); if (recursive) {
cout << "Available aircraft:" << endl; sort(aircraft.begin(), aircraft.end());
for ( unsigned int i = 0; i < aircraft.size(); i++ ) { cout << "Available aircraft:" << endl;
cout << aircraft[i] << endl; for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
} cout << aircraft[i] << endl;
}
aircraft.clear(); aircraft.clear();
ulCloseDir(dirp); }
ulCloseDir(dirp);
} }

View file

@ -33,6 +33,6 @@ extern void fgSetDefaults ();
extern void fgParseArgs (int argc, char ** argv); extern void fgParseArgs (int argc, char ** argv);
extern void fgParseOptions (const string &file_path); extern void fgParseOptions (const string &file_path);
extern void fgUsage (bool verbose = false); extern void fgUsage (bool verbose = false);
extern void fgShowAircraft(); extern void fgShowAircraft(const SGPath &path, bool recursive = true);
#endif /* _OPTIONS_HXX */ #endif /* _OPTIONS_HXX */