Author Topic: Apropos command for DS  (Read 2339 times)

Offline Archaegeo

  • Acquaintance
  • *
  • Posts: 33
    • View Profile
Apropos command for DS
« on: January 01, 2008, 08:41:59 pm »
The following code adds apropos support for DS. Note that this is limited, and will only search through the help indexed files.
Syntax: apropos <name>

I.E.
apropos scan

returns:
[creator commands]:  scan
[Autodoc functions]:  doc_d/scan_mudlib

This will really help folks looking for information and searching for help since you do not need to know the full help name or page through all the docs.  Also, if you use the autodoc system I posted earlier frequently, it makes scanning it quicker too.

Add the following function anywhere in /daemon/help.c
Code: [Select]
mapping AllIndices(){
  mapping ret;
  ret = Indices;
  return ret;
}

Make the following command /secure/cmds/creators/apropos.c
Code: [Select]
/* Do not remove the headers from this file! see /USAGE for more info. */
// Modified from Lima 1.05b by Archaegeo on 1/1/08 for Dead Souls Lib

#include <lib.h>
#include <daemons.h>
#define MIN_LEN 3

mixed apropos(string s);

mixed cmd(string s) {
    string yt;
    if (!s)
    {
        write("apropos <string>\n\n"
          "Returns information on which mudlib functions contain the\n"
          "keyword passed, including a short description.\n");
        return;
    }
    if (strlen(s)<MIN_LEN)
    {
        write("Please find a bigger search criteria (min. "+MIN_LEN+
          " letters).\n");
        return;
    }
    yt=apropos(s);
    if (yt=="\n")
        write("No help files match your word.\n");
    this_player()->eventPrint(yt);
    return 1;
}

//:COMMAND
//Returns information on which help files contain the
//keyword passed, including a short description.

mixed apropos(string s)
{
    mapping filer=([]);
    mapping topics;
    string output="";
    string *st;
    string pwd;

    topics=HELP_D->AllIndices();
    if(!topics)
    {
        error("Apropos whines about help_d not giving any info out.\n");
        return;
    }
    foreach (string key,string *files in topics)
    {
        foreach(string d in topics[key]) {
            if (strsrch(d,s)!=-1)
            {   
                output += "[" + key + "]:  " + d +"\n";
            }
        }
    }
    output+="\n";
    return output;
}

string GetHelp(string str) {
    return ("Syntax: <apropos <name>>\n\n"
      "Pages through the help file names that have been indexed for <name>.\n"+
      "See also: help index");
}

Enjoy