From 7ccba95b9c2fd4a6b2e4491dee26c951f748ce82 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 24 Oct 2010 01:09:06 +0100 Subject: [PATCH] Remove direct uses of PLIB ulXXX functions --- src/Airports/dynamics.cxx | 2 - src/GUI/new_gui.cxx | 90 +++++++++----------------- src/GUI/new_gui.hxx | 2 +- src/Input/FGCommonInput.hxx | 1 - src/Input/FGDeviceConfigurationMap.cxx | 38 +++++------ src/Input/FGDeviceConfigurationMap.hxx | 5 +- src/Network/ATC-Main.cxx | 4 +- src/Traffic/TrafficMgr.cxx | 46 ++++--------- 8 files changed, 63 insertions(+), 125 deletions(-) diff --git a/src/Airports/dynamics.cxx b/src/Airports/dynamics.cxx index f5ebd05d1..11cb454b9 100644 --- a/src/Airports/dynamics.cxx +++ b/src/Airports/dynamics.cxx @@ -26,8 +26,6 @@ #include -#include - #include #include #include diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index 034484e27..0e6346f0c 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -10,14 +10,13 @@ #include #include #include -#include #include -#include #include #include #include +#include #include @@ -56,11 +55,8 @@ void NewGUI::init () { setStyle(); - char path1[1024]; - char path2[1024]; - ulMakePath(path1, globals->get_fg_root().c_str(), "gui"); - ulMakePath(path2, path1, "dialogs"); - readDir(path2); + SGPath p(globals->get_fg_root(), "gui/dialogs"); + readDir(p); _menubar->init(); } @@ -233,19 +229,6 @@ NewGUI::setMenuBarVisible (bool visible) _menubar->hide(); } -static bool -test_extension (const char * path, const char * ext) -{ - int pathlen = strlen(path); - int extlen = strlen(ext); - - for (int i = 1; i <= pathlen && i <= extlen; i++) { - if (path[pathlen-i] != ext[extlen-i]) - return false; - } - return true; -} - void NewGUI::newDialog (SGPropertyNode* props) { @@ -260,49 +243,34 @@ NewGUI::newDialog (SGPropertyNode* props) } void -NewGUI::readDir (const char * path) +NewGUI::readDir (const SGPath& path) { - ulDir * dir = ulOpenDir(path); - - if (dir == 0) { - SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from " - << path); - return; - } - - for (ulDirEnt * dirEnt = ulReadDir(dir); - dirEnt != 0; - dirEnt = ulReadDir(dir)) { - - char subpath[1024]; - - ulMakePath(subpath, path, dirEnt->d_name); - - if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) { - SGPropertyNode * props = new SGPropertyNode; - try { - readProperties(subpath, props); - } catch (const sg_exception &) { - SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog " - << subpath); - delete props; - continue; - } - SGPropertyNode *nameprop = props->getNode("name"); - if (!nameprop) { - SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath - << " has no name; skipping."); - delete props; - continue; - } - string name = nameprop->getStringValue(); - if (_dialog_props[name]) - delete (SGPropertyNode *)_dialog_props[name]; - - _dialog_props[name] = props; - } + simgear::Dir dir(path); + simgear::PathList xmls = dir.children(simgear::Dir::TYPE_FILE, ".xml"); + + for (unsigned int i=0; igetNode("name"); + if (!nameprop) { + SG_LOG(SG_INPUT, SG_WARN, "dialog " << xmls[i].str() + << " has no name; skipping."); + delete props; + continue; + } + string name = nameprop->getStringValue(); + if (_dialog_props[name]) + delete (SGPropertyNode *)_dialog_props[name]; + + _dialog_props[name] = props; } - ulCloseDir(dir); } diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index 5932512fd..0797d53a6 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -219,7 +219,7 @@ private: void clear_colors(); // Read all the configuration files in a directory. - void readDir (const char * path); + void readDir (const SGPath& path); FGMenuBar * _menubar; FGDialog * _active_dialog; diff --git a/src/Input/FGCommonInput.hxx b/src/Input/FGCommonInput.hxx index 046ce8264..558510021 100644 --- a/src/Input/FGCommonInput.hxx +++ b/src/Input/FGCommonInput.hxx @@ -27,7 +27,6 @@ #include #include -#include #if defined( UL_WIN32 ) #define TGT_PLATFORM "windows" diff --git a/src/Input/FGDeviceConfigurationMap.cxx b/src/Input/FGDeviceConfigurationMap.cxx index 5ad2a0bd7..b8ce13505 100644 --- a/src/Input/FGDeviceConfigurationMap.cxx +++ b/src/Input/FGDeviceConfigurationMap.cxx @@ -30,8 +30,7 @@ #include "FGDeviceConfigurationMap.hxx" -#include - +#include #include #include
@@ -41,11 +40,8 @@ FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path, base(aBase), childname(aChildname) { - SGPath path(globals->get_fg_root()); - path.append( relative_path ); - int index = 1000; - scan_dir( path, &index); + scan_dir( SGPath(globals->get_fg_root(), relative_path), &index); PropertyList childNodes = base->getChildren(childname); for (int k = (int)childNodes.size() - 1; k >= 0; k--) { @@ -62,26 +58,22 @@ FGDeviceConfigurationMap::~FGDeviceConfigurationMap() base->removeChildren( childname ); } -void FGDeviceConfigurationMap::scan_dir( SGPath & path, int *index) +void FGDeviceConfigurationMap::scan_dir(const SGPath & path, int *index) { - ulDir *dir = ulOpenDir(path.c_str()); - if (dir) { - ulDirEnt* dent; - while ((dent = ulReadDir(dir)) != 0) { - if (dent->d_name[0] == '.') - continue; + simgear::Dir dir(path); + simgear::PathList children = dir.children(simgear::Dir::TYPE_FILE | + simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); - SGPath p(path.str()); - p.append(dent->d_name); - scan_dir(p, index); + for (unsigned int c=0; cgetChild(childname, (*index)++, true); + readProperties(path.str(), n); + n->setStringValue("source", path.c_str()); } - ulCloseDir(dir); - - } else if (path.extension() == "xml") { - SG_LOG(SG_INPUT, SG_DEBUG, "Reading joystick file " << path.str()); - SGPropertyNode_ptr n = base->getChild(childname, (*index)++, true); - readProperties(path.str(), n); - n->setStringValue("source", path.c_str()); } } diff --git a/src/Input/FGDeviceConfigurationMap.hxx b/src/Input/FGDeviceConfigurationMap.hxx index e89addc96..6a6aceae3 100644 --- a/src/Input/FGDeviceConfigurationMap.hxx +++ b/src/Input/FGDeviceConfigurationMap.hxx @@ -30,16 +30,17 @@ #endif #include -#include #include +class SGPath; + class FGDeviceConfigurationMap : public std::map { public: FGDeviceConfigurationMap ( const char * relative_path, SGPropertyNode_ptr base, const char * childname ); virtual ~FGDeviceConfigurationMap(); private: - void scan_dir( SGPath & path, int *index); + void scan_dir(const SGPath & path, int *index); SGPropertyNode_ptr base; const char * childname; }; diff --git a/src/Network/ATC-Main.cxx b/src/Network/ATC-Main.cxx index b70b4abf3..bdaf70936 100644 --- a/src/Network/ATC-Main.cxx +++ b/src/Network/ATC-Main.cxx @@ -31,6 +31,8 @@ #include #include #include +#include + #include //snprintf #ifdef _WIN32 # include //lseek, read, write @@ -38,8 +40,6 @@ #include -#include - #include #include #include diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index 615bb6c8c..d9fcb6fff 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -51,10 +51,9 @@ #include #include -#include - #include #include +#include #include #include #include @@ -126,41 +125,22 @@ FGTrafficManager::~FGTrafficManager() void FGTrafficManager::init() { - ulDir *d, *d2; - ulDirEnt *dent, *dent2; - heuristicsVector heuristics; HeuristicMap heurMap; if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) { - SGPath aircraftDir = globals->get_fg_root(); - SGPath path = aircraftDir; - - aircraftDir.append("AI/Traffic"); - if ((d = ulOpenDir(aircraftDir.c_str())) != NULL) { - while ((dent = ulReadDir(d)) != NULL) { - if (string(dent->d_name) != string(".") && - string(dent->d_name) != string("..") && dent->d_isdir) { - SGPath currACDir = aircraftDir; - currACDir.append(dent->d_name); - if ((d2 = ulOpenDir(currACDir.c_str())) == NULL) - return; - while ((dent2 = ulReadDir(d2)) != NULL) { - SGPath currFile = currACDir; - currFile.append(dent2->d_name); - if (currFile.extension() == string("xml")) { - SGPath currFile = currACDir; - currFile.append(dent2->d_name); - SG_LOG(SG_GENERAL, SG_DEBUG, - "Scanning " << currFile. - str() << " for traffic"); - readXML(currFile.str(), *this); - } - } - ulCloseDir(d2); - } - } - ulCloseDir(d); + simgear::Dir trafficDir(SGPath(globals->get_fg_root(), "AI/Traffic")); + simgear::PathList d = trafficDir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); + + for (unsigned int i=0; i