]> git.mxchange.org Git - flightgear.git/commitdiff
Use SGPath helpers and unescape from simgear
authorThomas Geymayer <tomgey@gmail.com>
Mon, 10 Jun 2013 19:42:53 +0000 (21:42 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 10 Jun 2013 19:42:53 +0000 (21:42 +0200)
src/Main/fg_init.cxx
src/Main/util.cxx
src/Main/util.hxx
src/Network/generic.cxx

index ec76fe987127135fdfb21145755eddc38db0b63f..436dd486d86d1f5a880d30b36288d7d99ff2940c 100644 (file)
@@ -390,12 +390,12 @@ SGPath platformDesktopPath()
   // failed, bad
   return SGPath();
     */
-    
+    // TODO real implementation and move to SGPath
     return SGPath(fgGetString("/sim/fg-current"));
 }
+#else
 
-#elif __APPLE__
-
+#ifdef __APPLE__
 #include <CoreServices/CoreServices.h>
 
 static SGPath platformDefaultDataPath()
@@ -405,58 +405,33 @@ static SGPath platformDefaultDataPath()
   if (err) {
     return SGPath();
   }
-  
+
   unsigned char path[1024];
   if (FSRefMakePath(&ref, path, 1024) != noErr) {
     return SGPath();
   }
-  
+
   SGPath appData;
   appData.set((const char*) path);
   appData.append("FlightGear");
   return appData;
 }
-
-SGPath platformDesktopPath()
-{
-  FSRef ref;
-  OSErr err = FSFindFolder(kUserDomain, kDesktopFolderType, false, &ref);
-  if (err) {
-    return SGPath();
-  }
-  
-  unsigned char path[1024];
-  if (FSRefMakePath(&ref, path, 1024) != noErr) {
-    return SGPath();
-  }
-  
-  return SGPath((const char*) path);
-}
-
 #else
 static SGPath platformDefaultDataPath()
 {
-  SGPath config( getenv("HOME") );
-  config.append( ".fgfs" );
-  return config;
+  return SGPath::home() / ".fgfs";
 }
-
+#endif
 SGPath platformDesktopPath()
 {
-  SGPath config( getenv("HOME") );
-  config.append( "Desktop" );
-  return config;
+  return SGPath::desktop();
 }
 #endif
 
 void fgInitHome()
 {
-    SGPath dataPath = platformDefaultDataPath();
-    const char *fg_home = getenv("FG_HOME");
-    if (fg_home)
-        dataPath = fg_home;
-    
-    globals->set_fg_home(dataPath.c_str());
+  SGPath dataPath = SGPath::fromEnv("FG_HOME", platformDefaultDataPath());
+  globals->set_fg_home(dataPath.c_str());
 }
 
 // Read in configuration (file and command line)
index 8efbb93fac80517ddf268d78175a1b4977f781fc..8dd2bd54d92566778e3d456fc754663ce33a998b 100644 (file)
@@ -71,59 +71,6 @@ fgGetLowPass (double current, double target, double timeratio)
     return current;
 }
 
-
-std::string
-fgUnescape (const char *s)
-{
-    std::string r;
-    while (*s) {
-        if (*s != '\\') {
-            r += *s++;
-            continue;
-        }
-        if (!*++s)
-            break;
-        if (*s == '\\') {
-            r += '\\';
-        } else if (*s == 'n') {
-            r += '\n';
-        } else if (*s == 'r') {
-            r += '\r';
-        } else if (*s == 't') {
-            r += '\t';
-        } else if (*s == 'v') {
-            r += '\v';
-        } else if (*s == 'f') {
-            r += '\f';
-        } else if (*s == 'a') {
-            r += '\a';
-        } else if (*s == 'b') {
-            r += '\b';
-        } else if (*s == 'x') {
-            if (!*++s)
-                break;
-            int v = 0;
-            for (int i = 0; i < 2 && isxdigit(*s); i++, s++)
-                v = v * 16 + (isdigit(*s) ? *s - '0' : 10 + tolower(*s) - 'a');
-            r += v;
-            continue;
-
-        } else if (*s >= '0' && *s <= '7') {
-            int v = *s++ - '0';
-            for (int i = 0; i < 3 && *s >= '0' && *s <= '7'; i++, s++)
-                v = v * 8 + *s - '0';
-            r += v;
-            continue;
-
-        } else {
-            r += *s;
-        }
-        s++;
-    }
-    return r;
-}
-
-
 // Write out path to validation node and read it back in. A Nasal
 // listener is supposed to replace the path with a validated version
 // or an empty string otherwise.
index acb25ac0d070c7d47c895ea1e9f00e529c79a56f..5e1aca890de268cbd8e468dd84eee11447067716 100644 (file)
  */
 extern double fgGetLowPass (double current, double target, double timeratio);
 
-
-/**
- * Unescape string.
- *
- * @param str String possibly containing escaped characters.
- * @return string with escaped characters replaced by single character values.
- */
-extern std::string fgUnescape (const char *str);
-
-
 /**
  * Validation listener interface for io.nas, used by fgcommands.
  * @param path Path to be validated
index 1ee76c33c3ba70d71086e9a3a238ef6d7cadc37c..f31484f166a2b97829873ac85a98edcba56cb142 100644 (file)
@@ -33,6 +33,7 @@
 #include <simgear/structure/exception.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/stdint.hxx>
+#include <simgear/misc/strutils.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
 #include <simgear/math/SGMath.hxx>
@@ -43,6 +44,8 @@
 #include <Main/util.hxx>
 #include "generic.hxx"
 
+using simgear::strutils::unescape;
+
 FGGeneric::FGGeneric(vector<string> tokens) : exitOnError(false), initOk(false)
 {
     size_t configToken;
@@ -591,10 +594,10 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
          * line_sep_string = the string/charachter to place at the end of each
          *                   lot of variables
          */
-        preamble = fgUnescape(root->getStringValue("preamble"));
-        postamble = fgUnescape(root->getStringValue("postamble"));
-        var_sep_string = fgUnescape(root->getStringValue("var_separator"));
-        line_sep_string = fgUnescape(root->getStringValue("line_separator"));
+        preamble = unescape(root->getStringValue("preamble"));
+        postamble = unescape(root->getStringValue("postamble"));
+        var_sep_string = unescape(root->getStringValue("var_separator"));
+        line_sep_string = unescape(root->getStringValue("line_separator"));
 
         if ( var_sep_string == "newline" ) {
             var_separator = '\n';
@@ -684,7 +687,7 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
         _serial_prot chunk;
 
         // chunk.name = chunks[i]->getStringValue("name");
-        chunk.format = fgUnescape(chunks[i]->getStringValue("format", "%d"));
+        chunk.format = unescape(chunks[i]->getStringValue("format", "%d"));
         chunk.offset = chunks[i]->getDoubleValue("offset");
         chunk.factor = chunks[i]->getDoubleValue("factor", 1.0);
         chunk.min = chunks[i]->getDoubleValue("min");