1
0
Fork 0

Remove direct uses of PLIB ulXXX functions

This commit is contained in:
James Turner 2010-10-24 01:09:06 +01:00
parent 0e53e2cbb1
commit 7ccba95b9c
8 changed files with 62 additions and 124 deletions

View file

@ -26,8 +26,6 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <plib/ul.h>
#include <Environment/environment_mgr.hxx> #include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx> #include <Environment/environment.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>

View file

@ -10,14 +10,13 @@
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <sys/types.h> #include <sys/types.h>
#include <plib/ul.h>
#include <plib/pu.h> #include <plib/pu.h>
#include <plib/ul.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
@ -56,11 +55,8 @@ void
NewGUI::init () NewGUI::init ()
{ {
setStyle(); setStyle();
char path1[1024]; SGPath p(globals->get_fg_root(), "gui/dialogs");
char path2[1024]; readDir(p);
ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
ulMakePath(path2, path1, "dialogs");
readDir(path2);
_menubar->init(); _menubar->init();
} }
@ -233,19 +229,6 @@ NewGUI::setMenuBarVisible (bool visible)
_menubar->hide(); _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 void
NewGUI::newDialog (SGPropertyNode* props) NewGUI::newDialog (SGPropertyNode* props)
{ {
@ -260,49 +243,34 @@ NewGUI::newDialog (SGPropertyNode* props)
} }
void void
NewGUI::readDir (const char * path) NewGUI::readDir (const SGPath& path)
{ {
ulDir * dir = ulOpenDir(path); simgear::Dir dir(path);
simgear::PathList xmls = dir.children(simgear::Dir::TYPE_FILE, ".xml");
if (dir == 0) { for (unsigned int i=0; i<xmls.size(); ++i) {
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from " SGPropertyNode * props = new SGPropertyNode;
<< path); try {
return; readProperties(xmls[i].str(), props);
} catch (const sg_exception &) {
SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
<< xmls[i].str());
delete props;
continue;
}
SGPropertyNode *nameprop = props->getNode("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;
} }
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;
}
}
ulCloseDir(dir);
} }

View file

@ -219,7 +219,7 @@ private:
void clear_colors(); void clear_colors();
// Read all the configuration files in a directory. // Read all the configuration files in a directory.
void readDir (const char * path); void readDir (const SGPath& path);
FGMenuBar * _menubar; FGMenuBar * _menubar;
FGDialog * _active_dialog; FGDialog * _active_dialog;

View file

@ -27,7 +27,6 @@
#include <vector> #include <vector>
#include <simgear/structure/SGBinding.hxx> #include <simgear/structure/SGBinding.hxx>
#include <plib/ul.h>
#if defined( UL_WIN32 ) #if defined( UL_WIN32 )
#define TGT_PLATFORM "windows" #define TGT_PLATFORM "windows"

View file

@ -30,8 +30,7 @@
#include "FGDeviceConfigurationMap.hxx" #include "FGDeviceConfigurationMap.hxx"
#include <plib/ul.h> #include <simgear/misc/sg_dir.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
@ -41,11 +40,8 @@ FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path,
base(aBase), base(aBase),
childname(aChildname) childname(aChildname)
{ {
SGPath path(globals->get_fg_root());
path.append( relative_path );
int index = 1000; int index = 1000;
scan_dir( path, &index); scan_dir( SGPath(globals->get_fg_root(), relative_path), &index);
PropertyList childNodes = base->getChildren(childname); PropertyList childNodes = base->getChildren(childname);
for (int k = (int)childNodes.size() - 1; k >= 0; k--) { for (int k = (int)childNodes.size() - 1; k >= 0; k--) {
@ -62,26 +58,22 @@ FGDeviceConfigurationMap::~FGDeviceConfigurationMap()
base->removeChildren( childname ); 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()); simgear::Dir dir(path);
if (dir) { simgear::PathList children = dir.children(simgear::Dir::TYPE_FILE |
ulDirEnt* dent; simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
while ((dent = ulReadDir(dir)) != 0) {
if (dent->d_name[0] == '.')
continue;
SGPath p(path.str()); for (unsigned int c=0; c<children.size(); ++c) {
p.append(dent->d_name); SGPath path(children[c]);
scan_dir(p, index); if (path.isDir()) {
scan_dir(path, index);
} 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());
} }
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());
} }
} }

View file

@ -30,16 +30,17 @@
#endif #endif
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/misc/sg_path.hxx>
#include <map> #include <map>
class SGPath;
class FGDeviceConfigurationMap : public std::map<std::string,SGPropertyNode_ptr> { class FGDeviceConfigurationMap : public std::map<std::string,SGPropertyNode_ptr> {
public: public:
FGDeviceConfigurationMap ( const char * relative_path, SGPropertyNode_ptr base, const char * childname ); FGDeviceConfigurationMap ( const char * relative_path, SGPropertyNode_ptr base, const char * childname );
virtual ~FGDeviceConfigurationMap(); virtual ~FGDeviceConfigurationMap();
private: private:
void scan_dir( SGPath & path, int *index); void scan_dir(const SGPath & path, int *index);
SGPropertyNode_ptr base; SGPropertyNode_ptr base;
const char * childname; const char * childname;
}; };

View file

@ -31,6 +31,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h>
#include <stdio.h> //snprintf #include <stdio.h> //snprintf
#ifdef _WIN32 #ifdef _WIN32
# include <io.h> //lseek, read, write # include <io.h> //lseek, read, write
@ -38,8 +40,6 @@
#include <string> #include <string>
#include <plib/ul.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/io/iochannel.hxx> #include <simgear/io/iochannel.hxx>

View file

@ -51,10 +51,9 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <plib/ul.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sg_dir.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/route/waypoint.hxx> #include <simgear/route/waypoint.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
@ -126,41 +125,22 @@ FGTrafficManager::~FGTrafficManager()
void FGTrafficManager::init() void FGTrafficManager::init()
{ {
ulDir *d, *d2;
ulDirEnt *dent, *dent2;
heuristicsVector heuristics; heuristicsVector heuristics;
HeuristicMap heurMap; HeuristicMap heurMap;
if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) { if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) {
SGPath aircraftDir = globals->get_fg_root(); simgear::Dir trafficDir(SGPath(globals->get_fg_root(), "AI/Traffic"));
SGPath path = aircraftDir; simgear::PathList d = trafficDir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
aircraftDir.append("AI/Traffic"); for (unsigned int i=0; i<d.size(); ++i) {
if ((d = ulOpenDir(aircraftDir.c_str())) != NULL) { simgear::Dir d2(d[i]);
while ((dent = ulReadDir(d)) != NULL) { simgear::PathList trafficFiles = d2.children(simgear::Dir::TYPE_FILE, ".xml");
if (string(dent->d_name) != string(".") && for (unsigned int j=0; j<trafficFiles.size(); ++j) {
string(dent->d_name) != string("..") && dent->d_isdir) { SGPath curFile = trafficFiles[j];
SGPath currACDir = aircraftDir; SG_LOG(SG_GENERAL, SG_DEBUG,
currACDir.append(dent->d_name); "Scanning " << curFile.str() << " for traffic");
if ((d2 = ulOpenDir(currACDir.c_str())) == NULL) readXML(curFile.str(), *this);
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);
} }
} else { } else {
fgSetBool("/sim/traffic-manager/heuristics", false); fgSetBool("/sim/traffic-manager/heuristics", false);