]> git.mxchange.org Git - flightgear.git/commitdiff
Remove direct uses of PLIB ulXXX functions
authorJames Turner <zakalawe@mac.com>
Sun, 24 Oct 2010 00:09:06 +0000 (01:09 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 24 Oct 2010 06:10:51 +0000 (07:10 +0100)
src/Airports/dynamics.cxx
src/GUI/new_gui.cxx
src/GUI/new_gui.hxx
src/Input/FGCommonInput.hxx
src/Input/FGDeviceConfigurationMap.cxx
src/Input/FGDeviceConfigurationMap.hxx
src/Network/ATC-Main.cxx
src/Traffic/TrafficMgr.cxx

index f5ebd05d1d397be6054fce286903cc3773e7c0d5..11cb454b97c5f8bdf851e6aa3ac81308d78b78d7 100644 (file)
@@ -26,8 +26,6 @@
 
 #include <simgear/compiler.h>
 
-#include <plib/ul.h>
-
 #include <Environment/environment_mgr.hxx>
 #include <Environment/environment.hxx>
 #include <simgear/misc/sg_path.hxx>
index 034484e27d106a9d686f5802f274f20f571edbc8..0e6346f0c709edfb8c32f7975665892221e4a432 100644 (file)
 #include <iostream>
 #include <cstring>
 #include <sys/types.h>
-#include <plib/ul.h>
 
 #include <plib/pu.h>
-#include <plib/ul.h>
 
 #include <simgear/compiler.h>
 #include <simgear/structure/exception.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/misc/sg_dir.hxx>
 
 #include <boost/algorithm/string/case_conv.hpp>
 
@@ -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; i<xmls.size(); ++i) {
+      SGPropertyNode * props = new SGPropertyNode;
+      try {
+          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;
     }
-    ulCloseDir(dir);
 }
 
 
index 5932512fdd33b29e8e683833c1f570617c8de2dd..0797d53a66ac8551f4b8adc9e0362b00fd832297 100644 (file)
@@ -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;
index 046ce8264c8355315574b972ee6f4ab87e3d9fb8..55851002168ae4098bf3c4c451d77a707b239bf6 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <vector>
 #include <simgear/structure/SGBinding.hxx>
-#include <plib/ul.h>
 
 #if defined( UL_WIN32 )
 #define TGT_PLATFORM   "windows"
index 5ad2a0bd7435f3786c0049777386bcce6ed52e91..b8ce13505f83d35c817ff13c73d2dc19ac887175 100644 (file)
@@ -30,8 +30,7 @@
 
 #include "FGDeviceConfigurationMap.hxx"
 
-#include <plib/ul.h>
-
+#include <simgear/misc/sg_dir.hxx>
 #include <simgear/props/props_io.hxx>
 #include <Main/globals.hxx>
 
@@ -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; c<children.size(); ++c) {
+    SGPath path(children[c]);
+    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());
   }
 }
 
index e89addc966b0ab6cf254850a490264577c91367e..6a6aceae3306582e11c44266287ba201ff938689 100644 (file)
 #endif
 
 #include <simgear/props/props.hxx>
-#include <simgear/misc/sg_path.hxx>
 
 #include <map>
 
+class SGPath;
+
 class FGDeviceConfigurationMap : public std::map<std::string,SGPropertyNode_ptr> {
 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;
 };
index b70b4abf36eb584ce1d6ffd726a8d093000c1f64..bdaf70936f40313a5ffa1158357c7f007ad65e55 100644 (file)
@@ -31,6 +31,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <errno.h>
+
 #include <stdio.h>              //snprintf
 #ifdef _WIN32
 #  include <io.h>                 //lseek, read, write
@@ -38,8 +40,6 @@
 
 #include <string>
 
-#include <plib/ul.h>
-
 #include <simgear/debug/logstream.hxx>
 #include <simgear/props/props_io.hxx>
 #include <simgear/io/iochannel.hxx>
index 615bb6c8c49e4275d337f539a744c1e8327e0972..d9fcb6fffcf2254d62113872e4770b5e319797ea 100644 (file)
 #include <vector>
 #include <algorithm>
 
-#include <plib/ul.h>
-
 #include <simgear/compiler.h>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/sg_dir.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/route/waypoint.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
@@ -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<d.size(); ++i) {
+          simgear::Dir d2(d[i]);
+          simgear::PathList trafficFiles = d2.children(simgear::Dir::TYPE_FILE, ".xml");
+          for (unsigned int j=0; j<trafficFiles.size(); ++j) {
+            SGPath curFile = trafficFiles[j];
+            SG_LOG(SG_GENERAL, SG_DEBUG,
+                  "Scanning " << curFile.str() << " for traffic");
+            readXML(curFile.str(), *this);
+          }
         }
     } else {
         fgSetBool("/sim/traffic-manager/heuristics", false);