Use SGPath helpers and unescape from simgear
This commit is contained in:
parent
50de7a8fbb
commit
dfa583c014
4 changed files with 18 additions and 103 deletions
|
@ -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()
|
||||
|
@ -416,47 +416,22 @@ static SGPath platformDefaultDataPath()
|
|||
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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue