diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index ec76fe987..436dd486d 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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 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) diff --git a/src/Main/util.cxx b/src/Main/util.cxx index 8efbb93fa..8dd2bd54d 100644 --- a/src/Main/util.cxx +++ b/src/Main/util.cxx @@ -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. diff --git a/src/Main/util.hxx b/src/Main/util.hxx index acb25ac0d..5e1aca890 100644 --- a/src/Main/util.hxx +++ b/src/Main/util.hxx @@ -39,16 +39,6 @@ */ 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 diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index 1ee76c33c..f31484f16 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,8 @@ #include
#include "generic.hxx" +using simgear::strutils::unescape; + FGGeneric::FGGeneric(vector 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");