summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/initfile.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-16 11:49:14 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-16 11:49:14 +0000
commiteff8860c8c5cf24ffb3ff64e4b44af416d72b3d4 (patch)
tree4249552fb843a2829a73261a5830fbc9909d4273 /crawl-ref/source/initfile.cc
parent97c0fc8f41703b81fe48a1323db8ad07b231cef0 (diff)
downloadcrawl-ref-eff8860c8c5cf24ffb3ff64e4b44af416d72b3d4.tar.gz
crawl-ref-eff8860c8c5cf24ffb3ff64e4b44af416d72b3d4.zip
Allow using aliases in init.txt:
a := autopickup_exceptions a = >decay, >degeneration git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1049 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/initfile.cc')
-rw-r--r--crawl-ref/source/initfile.cc70
1 files changed, 47 insertions, 23 deletions
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 88bd8946ba..84ac50bb1f 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -1049,6 +1049,8 @@ void game_options::read_options(InitLineInput &il, bool runscript)
bool l_init = false;
+ aliases.clear();
+
std::string luacond;
std::string luacode;
while (!il.eof())
@@ -1244,53 +1246,75 @@ int game_options::read_explore_stop_conditions(const std::string &field) const
return (conditions);
}
+void game_options::add_alias(const std::string &key, const std::string &val)
+{
+ aliases[key] = val;
+}
+
+std::string game_options::unalias(const std::string &key) const
+{
+ std::map<std::string, std::string>::const_iterator i = aliases.find(key);
+ return (i == aliases.end()? key : i->second);
+}
+
void game_options::read_option_line(const std::string &str, bool runscript)
{
std::string key = "";
std::string subkey = "";
std::string field = "";
- int first_equals = str.find('=');
- int first_dot = str.find('.');
-
bool plus_equal = false;
bool minus_equal = false;
+ const int first_equals = str.find('=');
+
// all lines with no equal-signs we ignore
if (first_equals < 0)
return;
- if (first_dot > 0 && first_dot < first_equals)
+ field = str.substr( first_equals + 1 );
+
+ std::string prequal = trimmed_string( str.substr(0, first_equals) );
+
+ // Is this a case of key += val?
+ if (prequal.length() && prequal[prequal.length() - 1] == '+')
{
- key = str.substr( 0, first_dot );
- subkey = str.substr( first_dot + 1, first_equals - first_dot - 1 );
- field = str.substr( first_equals + 1 );
+ plus_equal = true;
+ prequal = prequal.substr(0, prequal.length() - 1);
+ trim_string(prequal);
}
- else
+ else if (prequal.length() && prequal[prequal.length() - 1] == '-')
{
- // no subkey (dots are okay in value field)
- key = str.substr( 0, first_equals );
- subkey = "";
- field = str.substr( first_equals + 1 );
+ minus_equal = true;
+ prequal = prequal.substr(0, prequal.length() - 1);
+ trim_string(prequal);
}
+ else if (prequal.length() && prequal[prequal.length() - 1] == ':')
+ {
+ prequal = prequal.substr(0, prequal.length() - 1);
+ trim_string(prequal);
+ trim_string(field);
- // Clean up our data...
- tolower_string( trim_string( key ) );
+ add_alias(prequal, field);
+ return;
+ }
- // Is this a case of key += val?
- if (key.length() && key[key.length() - 1] == '+')
+ prequal = unalias(prequal);
+
+ const std::string::size_type first_dot = prequal.find('.');
+ if (first_dot != std::string::npos)
{
- plus_equal = true;
- key = key.substr(0, key.length() - 1);
- trim_string(key);
+ key = prequal.substr( 0, first_dot );
+ subkey = prequal.substr( first_dot + 1 );
}
- else if (key.length() && key[key.length() - 1] == '-')
+ else
{
- minus_equal = true;
- key = key.substr(0, key.length() - 1);
- trim_string(key);
+ // no subkey (dots are okay in value field)
+ key = prequal;
}
+ // Clean up our data...
+ tolower_string( trim_string( key ) );
tolower_string( trim_string( subkey ) );
// some fields want capitals... none care about external spaces