From 9d2782b8fb47b803a8feb167b86f7003a7db7bfb Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Fri, 23 Feb 2007 01:48:17 +0000 Subject: [PATCH] nsearch(), nlsearch(), and nchildren() functions --- game/txt/hlp/cobra_func.hlp | 8 ++++++++ src/function.c | 3 +++ src/wiz.c | 13 +++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/game/txt/hlp/cobra_func.hlp b/game/txt/hlp/cobra_func.hlp index ff45d05..ad0ed39 100644 --- a/game/txt/hlp/cobra_func.hlp +++ b/game/txt/hlp/cobra_func.hlp @@ -2113,12 +2113,17 @@ for an object named "Test", preferring a thing over other types. See also: pos() & LSEARCH() +& NLSEARCH() & SEARCH() +& NSEARCH() & LSEARCHR() & CHILDREN() +& NCHILDREN() lsearch([, [, ]]) + nlsearch([, [, ]]) lsearchr([, [, ]]) children() + nchildren() This function is similar to the @search command, except it returns just a list of dbref numbers. It is computationally expensive, and @@ -2135,6 +2140,9 @@ for an object named "Test", preferring a thing over other types. children() is exactly the same as lsearch(,parent,), using "all" for See_All/Search_All players and "me" for others. + nlsearch(...) and nchildren(...) return the count of results that + would be returned by lsearch() or children() with the same args. + See 'help lsearch2' for more details. & LSEARCH2 & SEARCH2 diff --git a/src/function.c b/src/function.c index 52afc12..cdc92a3 100644 --- a/src/function.c +++ b/src/function.c @@ -497,6 +497,7 @@ FUNTAB flist[] = { {"NAMEGRABALL", fun_namegraball, 2, 3, FN_REG}, {"NAND", fun_nand, 1, INT_MAX, FN_REG}, {"NATTR", fun_nattr, 1, 1, FN_REG}, + {"NCHILDREN", fun_lsearch, 1, 1, FN_REG}, {"NCON", fun_dbwalker, 1, 1, FN_REG}, {"NEXITS", fun_dbwalker, 1, 1, FN_REG}, {"NPLAYERS", fun_dbwalker, 1, 1, FN_REG}, @@ -508,11 +509,13 @@ FUNTAB flist[] = { {"NEARBY", fun_nearby, 2, 2, FN_REG}, {"NEQ", fun_neq, 2, 2, FN_REG}, {"NEXT", fun_next, 1, 1, FN_REG}, + {"NLSEARCH", fun_lsearch, 1, INT_MAX, FN_REG}, {"NOR", fun_nor, 1, INT_MAX, FN_REG}, {"NOT", fun_not, 1, 1, FN_REG}, #ifdef CHAT_SYSTEM {"NSCEMIT", fun_cemit, 2, 3, FN_REG}, #endif /* CHAT_SYSTEM */ + {"NSEARCH", fun_lsearch, 1, INT_MAX, FN_REG}, {"NSEMIT", fun_emit, 1, -1, FN_REG}, {"NSLEMIT", fun_lemit, 1, -1, FN_REG}, {"NSOEMIT", fun_oemit, 2, -2, FN_REG}, diff --git a/src/wiz.c b/src/wiz.c index ff011d7..e728538 100644 --- a/src/wiz.c +++ b/src/wiz.c @@ -1292,6 +1292,7 @@ do_search(dbref player, const char *arg1, char **arg3) FUNCTION(fun_lsearch) { int nresults; + int return_count = 0; dbref *results = NULL; int rev = !strcmp(called_as, "LSEARCHR"); @@ -1300,18 +1301,26 @@ FUNCTION(fun_lsearch) return; } - if (!strcmp(called_as, "CHILDREN")) { + if (called_as[0] == 'N') { + /* Return the count, not the values */ + return_count = 1; + } + + if (!strcmp(called_as, "CHILDREN") || !strcmp(called_as, "NCHILDREN")) { const char *myargs[2]; myargs[0] = "PARENT"; myargs[1] = args[0]; nresults = raw_search(executor, NULL, 2, myargs, &results, pe_info); - } else + } else { nresults = raw_search(executor, args[0], nargs - 1, (const char **) (args + 1), &results, pe_info); + } if (nresults < 0) { safe_str("#-1", buff, bp); + } else if (return_count) { + safe_integer(nresults, buff, bp); } else if (nresults == 0) { notify(executor, T("Nothing found.")); } else { -- 2.30.2