Cursing code

From: Templar Viper (templarviper@HOTMAIL.COM)
Date: 05/13/03


A while ago, I fixed this code together. It checks the argument for
cursing (placed in curse_list), and replaces it with a harmless beep. I
had to use str_strr, as strstr isn't case sensitive. However, I want to
ignore certain characters, such as spaces, full stops and more of those.
Here is the function:

int wordok(char *argument, bool call)
{
  int i;
  char temp[MAX_INPUT_LENGTH];

  /* return valid if list doesn't exist */
  if (!argument || curse_num < 1 || !curse_list)
 return (1);

  strlcpy(temp, argument, sizeof(temp));

  if (call) {
    /* Does the desired name contain a string in the curse list? */
    for (i = 0; i < curse_num; i++)
      if (str_strr(temp, curse_list[i]))
        return (0);
  } else
    for (i = 0; i < curse_num; i++)
   search_replace(argument, curse_list[i], "*beep*");


  return (1);
}

And str_strr:
/*
 * str_strr: a case-insensitive version of strstr(). */

char *str_strr(const char *str, const char *txt) {
  int chk = 0, i;

  if (str == NULL || txt == NULL)
    log("SYSERR: str_strr() passed a NULL pointer, %p or %p.", str, txt);
  else if (strlen(str) >= strlen(txt)) {
    for (i = 0; str[i]; i++) {
      if (LOWER(txt[chk]) == LOWER(str[i]))
        chk++;
      else
        chk = 0;

      if (chk == strlen(txt))
        return ((char *)(str)+i-chk+1);
 }
  }

  return (NULL);
}

I've got no idea however, to get this done. Any sugestions, hints, and
other help would be extremely helpfull :)

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/26/03 PDT