summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/command.cc
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-21 05:11:51 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2007-09-21 05:11:51 +0000
commite6f92f58fb62ddc074838485a4dac3ce5d068a8d (patch)
treeee54c4fa76b0f06d48e398e3d0faf5e1adb31880 /crawl-ref/source/command.cc
parent1640dccce5b2bab627f03607f80bfc7cd4b57327 (diff)
downloadcrawl-ref-e6f92f58fb62ddc074838485a4dac3ce5d068a8d.tar.gz
crawl-ref-e6f92f58fb62ddc074838485a4dac3ce5d068a8d.zip
Can now search the description database by name (keyword) with '?/'.
Not adding to 0.3-branch yet in case it needs some tweaks. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2170 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/command.cc')
-rw-r--r--crawl-ref/source/command.cc77
1 files changed, 74 insertions, 3 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index 8a234a49fc..26f55a4f0e 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -26,6 +26,8 @@
#include "abl-show.h"
#include "chardump.h"
#include "cio.h"
+#include "database.h"
+#include "describe.h"
#include "files.h"
#include "invent.h"
#include "itemname.h"
@@ -679,6 +681,65 @@ help_file help_files[] = {
{ NULL, 0, false }
};
+static void find_description()
+{
+ clrscr();
+ viewwindow(true, false);
+
+ mpr("Describe what? (can be a partial name or a regex) ");
+ char buf[80];
+ if (cancelable_get_line(buf, sizeof(buf)) || buf[0] == '\0')
+ {
+ canned_msg( MSG_OK);
+ return;
+ }
+
+ std::string regex = trimmed_string(buf);
+
+ if (regex == "")
+ {
+ mpr("Description must contain at least one non-space.");
+ return;
+ }
+
+ // Try to get an exact match first.
+ std::string key = regex;
+ std::string desc = getLongDescription(key);
+
+ if (desc == "")
+ {
+ std::vector<std::string> matches = getLongDescriptionByRegex(regex);
+
+ if (matches.size() == 0)
+ {
+ mprf("Nothing matches '%s'", buf);
+ return;
+ }
+ else if (matches.size() > 1)
+ {
+ std::string prefix = "No exact match for '" +
+ regex + "', possible matches are: ";
+
+ // Use mpr_comma_separated_list() because the list
+ // might be *LONG*.
+ mpr_comma_separated_list(prefix, matches, " and ", ", ",
+ MSGCH_PLAIN);
+ return;
+ }
+ else
+ {
+ // Only one match, use that.
+ key = matches[0];
+ desc = getLongDescription(key);
+ }
+ }
+ key = uppercase_first(key);
+ key += "$$";
+
+ clrscr();
+ print_description(key + desc);
+}
+
static int keyhelp_keyfilter(int ch)
{
switch (ch)
@@ -690,10 +751,19 @@ static int keyhelp_keyfilter(int ch)
display_notes();
return -1;
}
- // fall through
- default:
- return ch;
+ break;
+
+ case '/':
+ find_description();
+
+ if ( getch() == 0 )
+ getch();
+
+ viewwindow(true, false);
+
+ return -1;
}
+ return ch;
}
static void show_keyhelp_menu(const std::vector<formatted_string> &lines,
@@ -733,6 +803,7 @@ static void show_keyhelp_menu(const std::vector<formatted_string> &lines,
"<w>~</w>: Macros help\n"
"<w>!</w>: Options help\n"
"<w>%</w>: Table of aptitudes\n"
+ "<w>/</w>: Lookup description\n"
"<w>Home</w>: This screen\n",
true, true, cmdhelp_textfilter);