summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/configparser.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp
index 1373ae5af..495d38fff 100644
--- a/src/configparser.cpp
+++ b/src/configparser.cpp
@@ -18,7 +18,7 @@
struct Parser
{
ParseStack& stack;
- const int flags;
+ int flags;
FILE* const file;
fpos current;
fpos last_tag;
@@ -112,7 +112,7 @@ struct Parser
while (1)
{
ch = next();
- if (ch == '&')
+ if (ch == '&' && (flags & FLAG_USE_XML))
{
std::string varname;
while (1)
@@ -134,6 +134,16 @@ struct Parser
throw CoreException("Undefined XML entity reference '&" + varname + ";'");
value.append(var->second);
}
+ else if (ch == '\\' && !(flags & FLAG_USE_XML))
+ {
+ int esc = next();
+ if (esc == 'n')
+ value.push_back('\n');
+ else if (isalpha(esc))
+ throw CoreException("Unknown escape character \\" + std::string(1, esc));
+ else
+ value.push_back(esc);
+ }
else if (ch == '"')
break;
else
@@ -169,12 +179,24 @@ struct Parser
}
else if (name == "define")
{
+ if (!(flags & FLAG_USE_XML))
+ throw CoreException("<define> tags may only be used in XML-style config (add <config format=\"xml\">)");
std::string varname = tag->getString("name");
std::string value = tag->getString("value");
if (varname.empty())
throw CoreException("Variable definition must include variable name");
stack.vars[varname] = value;
}
+ else if (name == "config")
+ {
+ std::string format = tag->getString("format");
+ if (format == "xml")
+ flags |= FLAG_USE_XML;
+ else if (format == "compat")
+ flags &= ~FLAG_USE_XML;
+ else if (!format.empty())
+ throw CoreException("Unknown configuration format " + format);
+ }
else
{
stack.output.insert(std::make_pair(name, tag));