diff --git a/Settings.cpp b/Settings.cpp index abf8ad2..11d473b 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -1,4 +1,5 @@ +#include #include "Settings.h" static std::string trim(const std::string s) @@ -51,31 +52,16 @@ bool Settings::getGeneric(std::string key, std::string *pvalue) m_file.seekg(0); for (std::getline(m_file,line); m_file.good(); std::getline(m_file,line)) { linenr++; - std::istringstream iline; - iline.str(line); - iline >> std::skipws; - std::string variable; - std::string eq; - iline >> variable; - if (variable != key) + size_t keylen = line.find_first_of('='); + if (keylen == std::string::npos) { + std::cerr << "Error parsing config line at " << m_filename << ":" << linenr << ": expected: = ('=' not found)"; + continue; + } + if (trim(line.substr(0, keylen)) != key) continue; found = true; - iline >> eq; - if (m_file.fail() || eq != "=") { - std::ostringstream oss; - oss << "Error parsing '" << key << "' in file " << m_messageName << " at line " << linenr << " (missing '=')"; - throw std::runtime_error(oss.str()); - } - if (pvalue) { - std::string value; - iline >> value; - if (m_file.fail()) { - std::ostringstream oss; - oss << "Error parsing value for '" << key << "' in file " << m_messageName << " at line " << linenr; - throw std::runtime_error(oss.str()); - } - *pvalue = trim(value); - } + if (pvalue) + *pvalue = trim(line.substr(keylen + 1)); } return found; } diff --git a/db-postgresql.cpp b/db-postgresql.cpp index 72a398a..95bf5b8 100644 --- a/db-postgresql.cpp +++ b/db-postgresql.cpp @@ -30,6 +30,8 @@ DBPostgreSQL::DBPostgreSQL(const std::string &mapdir) : if (!info_found) throw std::runtime_error("Set postgresql_connection_info or pg_connection_info in world.mt to use the postgresql backend"); + connection_info += "fallback_application_name=minetestmapper " + connection_info; + m_connection = PQconnectdb(connection_info.c_str()); if (PQstatus(m_connection) != CONNECTION_OK) { throw std::runtime_error(std::string("Failed to connect to postgresql database: ")