summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/database.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-01-26 07:31:00 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-01-26 07:31:00 +0000
commitaa300c86ccbb1cffa03ee8f6e0dca0e6ef48cef6 (patch)
tree026a78d32326ca88f029ddc0949b799e39317f3c /crawl-ref/source/database.cc
parent32a6373c7a8072bfcb4567417f82f700084b6ab8 (diff)
downloadcrawl-ref-aa300c86ccbb1cffa03ee8f6e0dca0e6ef48cef6.tar.gz
crawl-ref-aa300c86ccbb1cffa03ee8f6e0dca0e6ef48cef6.zip
Added help for stash-search (dpeg).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3338 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r--crawl-ref/source/database.cc57
1 files changed, 34 insertions, 23 deletions
diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc
index ff1b59bf2c..04accbd4f3 100644
--- a/crawl-ref/source/database.cc
+++ b/crawl-ref/source/database.cc
@@ -35,6 +35,7 @@ enum db_id
{
DB_SHOUT,
DB_SPEAK,
+ DB_HELP,
MAX_DBID
};
@@ -50,7 +51,8 @@ struct SingleFileDB
SingleFileDB singleFileDBs[MAX_DBID] =
{
SingleFileDB("shout"),
- SingleFileDB("speak")
+ SingleFileDB("speak"),
+ SingleFileDB("help")
};
#define DESC_BASE_NAME "descript"
@@ -233,10 +235,8 @@ static void execute_embedded_lua(std::string &str)
if (clua.execstring(lua.c_str(), "db_embedded_lua", 1))
{
- std::string err = "{{" + clua.error;
- err += "}}";
+ std::string err = "{{" + clua.error + "}}";
str.replace(pos, lua_full.length(), err);
-
return;
}
@@ -249,11 +249,6 @@ static void execute_embedded_lua(std::string &str)
} // while (pos != std::string::npos)
}
-static void trim_right(std::string &s)
-{
- s.erase(s.find_last_not_of(" \r\t\n") + 1);
-}
-
static void trim_leading_newlines(std::string &s)
{
s.erase(0, s.find_first_not_of("\n"));
@@ -310,7 +305,7 @@ static void parse_text_db(std::ifstream &inf, DBM *db)
else
{
std::string line = buf;
- trim_right(line);
+ trim_string_right(line);
value += line + "\n";
}
}
@@ -478,6 +473,27 @@ static std::string getRandomizedStr(DBM *database, const std::string &key,
return str;
}
+static std::string query_database(DBM *db, std::string key,
+ bool canonicalise_key, bool run_lua)
+{
+ if (canonicalise_key)
+ {
+ // We have to canonicalize the key (in case the user typed it
+ // in and got the case wrong.)
+ lowercase(key);
+ }
+
+ // Query the DB.
+ datum result = database_fetch(db, key);
+
+ std::string str((const char *)result.dptr, result.dsize);
+
+ if (run_lua)
+ execute_embedded_lua(str);
+
+ return (str);
+}
+
/////////////////////////////////////////////////////////////////////////////
// Description DB specific functions.
@@ -486,19 +502,7 @@ std::string getLongDescription(const std::string &key)
if (!descriptionDB)
return ("");
- // We have to canonicalize the key (in case the user typed it
- // in and got the case wrong.)
- std::string canonical_key = key;
- lowercase(canonical_key);
-
- // Query the DB.
- datum result = database_fetch(descriptionDB, canonical_key);
-
- // Cons up a (C++) string to return. The caller must release it.
- std::string str((const char *)result.dptr, result.dsize);
-
- execute_embedded_lua(str);
- return (str);
+ return query_database(descriptionDB, key, true, true);
}
std::vector<std::string> getLongDescKeysByRegex(const std::string &regex,
@@ -598,3 +602,10 @@ std::string getSpeakString(const std::string &monst)
return getRandomizedStr(get_dbm(DB_SPEAK), monst, "", num_replacements);
}
+/////////////////////////////////////////////////////////////////////////////
+// Help DB specific functions.
+
+std::string getHelpString(const std::string &topic)
+{
+ return query_database(get_dbm(DB_HELP), topic, false, true);
+}