Re: A helpcheck command

From: James Turner (turnerjh@XTN.NET)
Date: 04/20/98


Angus Mezick <angus@EDGIL.CCMAIL.COMPUSERVE.COM> writes:

> Saga,
> nifty idea, but one question, what is help_lookup()?  did you just yank the code
> out of do_help or something?  If so, not that hard to code on my own, but your
> snippet needs it to function.
> --Angus

Ahh I meant to send that correction in after I posted, but got
distracted in the other threads.  Yes, I did pull it from do_help;
I've included it below.  Also, the data structures I used (CHAR_DATA)
are not included in stock.  As I mentioned in another thread, I've
replaced mine (saves on typing and IMO reduces clutter).  Sorry it
wasn't posted in a more useable form.

/*
   Given a string s, it returns the index in the help_table of the
   help entry for that string, or -1 on failure.
 */

int
help_lookup(char *s)
{
  int chk, bot, top, mid, minlen;

  if (!help_table) {
    return -1;
  }

  bot = 0;
  top = top_of_helpt;
  minlen = strlen(s);

  for (;;) {
    mid = (bot + top) / 2;

    if (bot > top) {
      return -1;
    }
    else if (!(chk = strn_cmp(s, help_table[mid].keyword, minlen))) {
      /* trace backwards to find first matching entry. Thanks Jeff
         Fink!  */
      while ((mid > 0) &&
           (!(chk = strn_cmp(s, help_table[mid - 1].keyword, minlen))))
        mid--;
      return mid;
    }
    else {
      if (chk > 0)
        bot = mid + 1;
      else
        top = mid - 1;
    }
  }
}


--
James Turner               turnerjh@xtn.net
                           http://www.vuse.vanderbilt.edu/~turnerj1/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST