From 92440592b0d254747dd8e4ce4e290223d97af04c Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Sun, 15 May 2011 16:37:15 -0400 Subject: [PATCH] PennMUSH 1.8.3p12 Author: talvo@talvo.com Date: Sat Jan 30 08:36:51 2010 +0000 Issue 178, new 'x' option for locate() to only do exact-name matches Fixes #209 --- hdrs/match.h | 1 + src/fundb.c | 5 ++++- src/match.c | 11 ++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hdrs/match.h b/hdrs/match.h index 96a6905..e21a11f 100644 --- a/hdrs/match.h +++ b/hdrs/match.h @@ -30,6 +30,7 @@ #define MAT_NOISY 0x1000000 #define MAT_LAST 0x2000000 #define MAT_TYPE 0x4000000 /* don't accept objects of other types */ +#define MAT_EXACT 0x8000000 /* don't do partial name matches */ /* groups of things to match */ #define MAT_EVERYTHING (MAT_ME|MAT_HERE|MAT_ABSOLUTE|MAT_PLAYER| \ MAT_NEIGHBOR|MAT_POSSESSION|MAT_EXIT|MAT_ENGLISH) diff --git a/src/fundb.c b/src/fundb.c index b6ce0a4..ef6f715 100644 --- a/src/fundb.c +++ b/src/fundb.c @@ -1980,6 +1980,9 @@ FUNCTION(fun_locate) case 'z': match_flags |= MAT_ENGLISH; break; + case 'x': + match_flags |= MAT_EXACT; + break; case 'X': ambig_ok = 1; /* okay to pick last match */ break; @@ -1993,7 +1996,7 @@ FUNCTION(fun_locate) if (!pref_type) pref_type = NOTYPE; - if (!(match_flags & ~(MAT_CHECK_KEYS | MAT_TYPE))) + if (!(match_flags & ~(MAT_CHECK_KEYS | MAT_TYPE | MAT_EXACT))) match_flags |= MAT_EVERYTHING; /* report the results */ diff --git a/src/match.c b/src/match.c index 5427f6e..e024aac 100644 --- a/src/match.c +++ b/src/match.c @@ -33,6 +33,7 @@ * MAT_REMOTE_CONTENTS - match the contents of a remote location * MAT_ENGLISH - match natural english 'my 2nd flower' * MAT_TYPE - match only objects of the given type(s) + * MAT_EXACT - only do full-name matching, no partial names * MAT_EVERYTHING - me,here,absolute,player,neighbor,possession,exit * MAT_NEARBY - everything near * MAT_OBJECTS - me,absolute,player,neigbor,possession @@ -58,7 +59,7 @@ #include "attrib.h" static int parse_english(char **name, long *flags); -static dbref match_player(dbref who, const char *name); +static dbref match_player(dbref who, const char *name, int partial); extern int check_alias(const char *command, const char *list); /* game.c */ static int match_aliases(dbref match, const char *name); static dbref choose_thing(const dbref who, const int preferred_type, long flags, dbref thing1, dbref thing2); @@ -198,7 +199,7 @@ static dbref debugMatchTo = 1; } else if (match_aliases(match, name) || (!IsExit(match) && !strcasecmp(Name(match), name))) { \ /* exact name match */ \ MATCHED(1); \ - } else if ((!exact || !GoodObject(bestmatch)) && !IsExit(match) && string_match(Name(match), name)) { \ + } else if (!(flags & MAT_EXACT) && (!exact || !GoodObject(bestmatch)) && !IsExit(match) && string_match(Name(match), name)) { \ /* partial name match */ \ MATCHED(0); \ } \ @@ -268,7 +269,7 @@ choose_thing(const dbref who, const int preferred_type, long flags, dbref thing1 } static dbref -match_player(dbref who, const char *name) { +match_player(dbref who, const char *name, int partial) { dbref match; if (*name == LOOKUP_TOKEN) { @@ -283,7 +284,7 @@ match_player(dbref who, const char *name) { if (match != NOTHING) { return match; } - return (GoodObject(who) ? visible_short_page(who, name) : NOTHING); + return (GoodObject(who) && partial ? visible_short_page(who, name) : NOTHING); } static int @@ -346,7 +347,7 @@ match_result(dbref who, const char *xname, int type, long flags) if (((flags & MAT_PMATCH) || ((flags & MAT_PLAYER) && *xname == LOOKUP_TOKEN)) && ((type & TYPE_PLAYER) || !(flags & MAT_TYPE))) { - match = match_player(who, xname); + match = match_player(who, xname, !(flags & MAT_EXACT)); if (GoodObject(match)) { if (MATCH_CONTROLS) { return match; -- 2.30.2