[CODE] Globally Handle Abbreviations

From: Cj Stremick (stremick@ix.netcom.com)
Date: 02/11/99


Hi, guys.  Enough people asked for it, I'll just post this to the list.

It works like this - It'll find an abbreviation anywhere in a =
space-separated list.  So calling it on:
PUT JUI CH (put juicy chest)
"JUI", "APPLE RED JUICY"
-or-
"CH", "BOX CHEST"
will work well.

Remember - this is certainly not as efficient as it should be.  Also, =
it's the first time in a couple years I've looked at it and I just =
noticed I made my own "tolower" function called "lcase".  Why?  Beats =
me!  Probably too much Visual Basic during the days...;-)  Anyway, =
that's included too.

What to do?  Comment out the stock "isname" function (it's in handler.c) =
and plug the two included functions in.  Since the arg list is the same, =
the calls should not need to be changed.  I think that's all.

Oh - and if anyone tightens this up, please post it back to the list.

I have to go.  I'm hungry for an apple all the sudden...

-Cj
http://dibrova.betterbox.net/~dibrova/

--8<--
/* This is a replacement to the stock func. */
/* str is what the person typed. */
/* namelist is one string [with many words sep'd by spaces]. */
int isname(char *str, char *namelist)
{
  char *arg1; /* Points to the keyword. */
  char *arg2; /* Points to the list. */
  char keyword[256];
  char nl[512];
  char wrd[128];
  char *pts;
  int i;
  int wp = 0;
  int sl =  strlen(namelist);

  strcpy(keyword, str);
  strcpy(nl, namelist);
  arg1=lcase(keyword);
  arg2=lcase(nl);

  if(!strcmp(str, namelist))
    return 1; /* Exact - bail out now. */

  for (i=0; i<sl;i++){
    if (arg2[i]==' ' || arg2[i]=='\0') {
      wrd[wp]='\0';
      pts=wrd;
      if (is_abbrev(arg1, pts)) return 1; /* Stop looking. and return true */
      wp=0;
    }else{
      wrd[wp++]=arg2[i];
    }
  }
  wrd[wp]='\0';
  pts=wrd;
  if (is_abbrev(arg1, pts)){
    return 1;
  }else{
    return 0;
  }
}

/* CMS - Convert a string to lower case */
char *lcase(char *str)
{
  char *p;

  for (p=str; *p; p++){
    *p=tolower(*p);
  }
  return str;
}

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



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