From 94c42a1d74076a4767ed7d3c1394adb813e817d7 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Sat, 22 Sep 2007 02:48:12 +0000 Subject: 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 --- crawl-ref/source/database.cc | 50 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'crawl-ref/source/database.cc') 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 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 database_find_keys(DBM *database, return (matches); } +std::vector database_find_bodies(DBM *database, + const std::string ®ex, + bool ignore_case) +{ + text_pattern tpat(regex, ignore_case); + std::vector 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 getLongDescriptionByRegex(const std::string ®ex) +std::vector getLongDescKeysByRegex(const std::string ®ex) { if (!descriptionDB) { @@ -436,6 +473,17 @@ std::vector getLongDescriptionByRegex(const std::string ®ex) return database_find_keys(descriptionDB, regex, true); } +std::vector getLongDescBodiesByRegex(const std::string ®ex) +{ + if (!descriptionDB) + { + std::vector empty; + return (empty); + } + + return database_find_bodies(descriptionDB, regex, true); +} + static std::vector description_txt_paths() { std::vector txt_file_names; -- cgit v1.2.3-54-g00ecf