summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/database.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-22 02:48:12 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-22 02:48:12 +0000
commit94c42a1d74076a4767ed7d3c1394adb813e817d7 (patch)
treeec513b612f05f80d4c313430074b7dcc91ab3361 /crawl-ref/source/database.cc
parenta0fc101bb8397b81ccd9cf5c1137764e14c57e89 (diff)
downloadcrawl-ref-94c42a1d74076a4767ed7d3c1394adb813e817d7.tar.gz
crawl-ref-94c42a1d74076a4767ed7d3c1394adb813e817d7.zip
If there are multiple matches to the "?/" describe command, then
they will be displayed in a menu, which the user can select from. Menu entries for monsters will be given the same color as the monster, with the monster's symbol added to the end of the string. Entering a single character as input to the "?/" describe command lists all monsters with that display symbol. Monsters sharing the same display symbol can now have the same string appended or prepended to their description (implemented to make the "?/" command have to deal with less special cases). Currently only used by nagas with __N_suffix. Has the side-effect advantage that the naga subspicies description and the "attractive/repulsive" description goes before the big block of quoted text, rather than after it. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2177 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/database.cc')
-rw-r--r--crawl-ref/source/database.cc50
1 files changed, 49 insertions, 1 deletions
diff --git a/crawl-ref/source/database.cc b/crawl-ref/source/database.cc
index 6de91c3a1e..86ae4b098c 100644
--- a/crawl-ref/source/database.cc
+++ b/crawl-ref/source/database.cc
@@ -165,6 +165,12 @@ std::vector<std::string> database_find_keys(DBM *database,
{
std::string key((const char *)dbKey.dptr, dbKey.dsize);
+ if (key.find("__") != std::string::npos)
+ {
+ dbKey = dbm_nextkey(database);
+ continue;
+ }
+
if (tpat.matches(key))
matches.push_back(key);
@@ -174,6 +180,37 @@ std::vector<std::string> database_find_keys(DBM *database,
return (matches);
}
+std::vector<std::string> database_find_bodies(DBM *database,
+ const std::string &regex,
+ bool ignore_case)
+{
+ text_pattern tpat(regex, ignore_case);
+ std::vector<std::string> matches;
+
+ datum dbKey = dbm_firstkey(database);
+
+ while (dbKey.dptr != NULL)
+ {
+ std::string key((const char *)dbKey.dptr, dbKey.dsize);
+
+ if (key.find("__") != std::string::npos)
+ {
+ dbKey = dbm_nextkey(database);
+ continue;
+ }
+
+ datum dbBody = dbm_fetch(database, dbKey);
+ std::string body((const char *)dbBody.dptr, dbBody.dsize);
+
+ if (tpat.matches(body))
+ matches.push_back(key);
+
+ dbKey = dbm_nextkey(database);
+ }
+
+ return (matches);
+}
+
///////////////////////////////////////////////////////////////////////////
// Internal DB utility functions
static void trim_right(std::string &s)
@@ -425,7 +462,7 @@ std::string getLongDescription(const std::string &key)
return std::string((const char *)result.dptr, result.dsize);
}
-std::vector<std::string> getLongDescriptionByRegex(const std::string &regex)
+std::vector<std::string> getLongDescKeysByRegex(const std::string &regex)
{
if (!descriptionDB)
{
@@ -436,6 +473,17 @@ std::vector<std::string> getLongDescriptionByRegex(const std::string &regex)
return database_find_keys(descriptionDB, regex, true);
}
+std::vector<std::string> getLongDescBodiesByRegex(const std::string &regex)
+{
+ if (!descriptionDB)
+ {
+ std::vector<std::string> empty;
+ return (empty);
+ }
+
+ return database_find_bodies(descriptionDB, regex, true);
+}
+
static std::vector<std::string> description_txt_paths()
{
std::vector<std::string> txt_file_names;