ok, in the way of str_cmp, str_dup, strn_cmp, et al.
I have created a str_str() function that works correctly.
It's taken me awhile, but it requires nothing else
than is_abbrev() (which is stock anyway) and it works fine for me :-)
btw, I finally converted all the functions to check == LOWER instead
of modifying the string. Maybe this function should be stock also???
*nudge George*
anyway, here it is, it's a short one.
put this prototype in utils.h
char *str_str(char *arg1, char *arg2);
Begin Code (put it in utils.c)-------
// str_str: a case-insensitive version of strstr()
// scans arg1 for the first occurrence of the substring arg2
// returns a pointer to the point in arg1 where arg2 begins.
// If arg2 does not occur in arg1, str_str returns NULL.
// Written by Akuma the Raging Coder
char *str_str(char *arg1, char *arg2)
{
register int iptr;
register int len1;
register int len2;
if (!arg1 && !arg2)
{ log("NULL arg1 and arg2 passed to %s().", __FUNCTION__); return NULL; }
else if (!arg1)
{ log("NULL arg1 passed to %s().", __FUNCTION__); return NULL; }
else if (!arg2)
{ log("NULL arg2 passed to %s().", __FUNCTION__); return NULL; }
len1 = str_len(arg2);
len2 = str_len(arg1);
// if str_len(arg2) is greater than str_len(arg1),
// then arg2 can't be substring of arg1
if (len1 > len2)
return NULL;
else if (len1 == len2) {
if (!str_cmp(arg1, arg2))
return (arg1);
else return NULL;
}
for (iptr = 0; iptr <= len2 - len1; iptr++) {
if (LOWER(*arg2) == LOWER(*(arg1+iptr)) &&
is_abbrev(arg2, (arg1 + iptr)))
return (arg1+iptr);
}
// Obviously we reached the end, and nothing was found.
return NULL;
}
-----End Code
Anyway, think about making this a stock addition, along with changing
one_argument, et al to check == LOWER(*ptr) instead of modifying the string.
of course, it requires that small modification from functions like
any_one_arg all the way to search_block().
so, that's it. Just leave my name in the comment,
and that'll be fine with me. :-)
Code On
Akuma the Raging Coder
+------------------------------------------------------------+
| "The poets talk about love, but what I talk about is DOOM, |
| because in the end, DOOM is all that counts." - |
| Alex Machine/George Stark/Stephen King, The Dark Half |
| "Nothing is IMPOSSIBLE, Just IMPROBABLE" |
| "Easier Said Than Done, But Better Done Than Said..." |
+------------------------------------------------------------+
+------------------------------------------------------------+
| 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