Skip to content

Commit

Permalink
Fix/Config: Allow for multi-word values
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Jan 22, 2024
1 parent c6f8726 commit cf49d20
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions src/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ XPMPPlaneID GlobVars::NextPlaneId ()
/// @details Goal is to provide some few configuration options independend
/// of the plugin using XPMP2. This is useful e.g. when configuring
/// non-standard network settings for remote connections.\n
/// For even greate flexibility the function will try a plugin-specific
/// For even greater flexibility the function will try a plugin-specific
/// file first, named "XPMP2.<logAcronym>.prf" (with spaces replaced
/// with underscores) and if that is not found
/// it tries the generic file "XPMP2.prf".\n
Expand Down Expand Up @@ -87,7 +87,6 @@ void GlobVars::ReadConfigFile ()
}

// Read from the file
std::vector<std::string> ln;
std::string lnBuf;
int errCnt = 0;
while (fIn && errCnt <= 3) {
Expand All @@ -96,43 +95,45 @@ void GlobVars::ReadConfigFile ()
lnBuf[0] == '#')
continue;

// otherwise should be 2 tokens
ln = str_tokenize(lnBuf, " ");
if (ln.size() != 2) {
// wrong number of words in that line
LOG_MSG(logWARN,"Expected two words (key, value) in config file '%s', line '%s' -> ignored",
cfgFileName.c_str(), lnBuf.c_str());
// otherwise should be 2 tokens, separated by the first space
size_t spcPos = lnBuf.find(" ");
if (spcPos == std::string::npos || spcPos == 0 || spcPos == lnBuf.length()-1) {
// Too few words in that line
LOG_MSG(logWARN, "Expected at least two words (key, value) in config file '%s', line '%s' -> ignored",
cfgFileName.c_str(), lnBuf.c_str());
errCnt++;
continue;
}
const std::string sKey = lnBuf.substr(0, spcPos);
std::string sVal = lnBuf.substr(spcPos + 1);

// *** Process actual configuration entries ***

int iVal = 0;
try {iVal = (int) std::stol(ln[1]); }
try {iVal = (int) std::stol(sVal); }
catch (...) { iVal = 0; }
if (ln[0] == "logLvl") logLvl = (logLevelTy) clamp<int>(iVal, int(logDEBUG), int(logFATAL));
else if (ln[0] == "defaultICAO") defaultICAO = ln[1];
else if (ln[0] == "carIcaoType") carIcaoType = ln[1];
else if (ln[0] == "remoteSupport") {
str_tolower(ln[1]);
if (ln[1] == "on") glob.remoteCfg = glob.remoteCfgFromIni = REMOTE_CFG_ON;
else if (ln[1] == "auto") glob.remoteCfg = glob.remoteCfgFromIni = REMOTE_CFG_AUTO;
else if (ln[1] == "off") glob.remoteCfg = glob.remoteCfgFromIni = REMOTE_CFG_OFF;
if (sKey == "logLvl") logLvl = (logLevelTy) clamp<int>(iVal, int(logDEBUG), int(logFATAL));
else if (sKey == "defaultICAO") defaultICAO = sVal;
else if (sKey == "carIcaoType") carIcaoType = sVal;
else if (sKey == "remoteSupport") {
str_tolower(sVal);
if (sVal == "on") glob.remoteCfg = glob.remoteCfgFromIni = REMOTE_CFG_ON;
else if (sVal == "auto") glob.remoteCfg = glob.remoteCfgFromIni = REMOTE_CFG_AUTO;
else if (sVal == "off") glob.remoteCfg = glob.remoteCfgFromIni = REMOTE_CFG_OFF;
else {
LOG_MSG(logWARN, "Ignored unknown value '%s' for 'remoteSupport' in file '%s'",
ln[1].c_str(), cfgFileName.c_str());
sVal.c_str(), cfgFileName.c_str());
}
}
else if (ln[0] == "remoteMCGroup") remoteMCGroup = ln[1];
else if (ln[0] == "remotePort") remotePort = iVal;
else if (ln[0] == "remoteSendIntf") remoteSendIntf = ln[1];
else if (ln[0] == "remoteTTL") remoteTTL = iVal;
else if (ln[0] == "remoteBufSize") remoteBufSize = (size_t)iVal;
else if (ln[0] == "remoteTxfFrequ") remoteTxfFrequ = iVal;
else if (sKey == "remoteMCGroup") remoteMCGroup = sVal;
else if (sKey == "remotePort") remotePort = iVal;
else if (sKey == "remoteSendIntf") remoteSendIntf = sVal;
else if (sKey == "remoteTTL") remoteTTL = iVal;
else if (sKey == "remoteBufSize") remoteBufSize = (size_t)iVal;
else if (sKey == "remoteTxfFrequ") remoteTxfFrequ = iVal;
else {
LOG_MSG(logWARN, "Ignored unknown config item '%s' from file '%s'",
ln[0].c_str(), cfgFileName.c_str());
sKey.c_str(), cfgFileName.c_str());
}
}

Expand Down

0 comments on commit cf49d20

Please sign in to comment.