Re: Redoing Advance...

From: Daniel A. Koepke (
Date: 11/09/01

On Sat, 10 Nov 2001, Pj Bean wrote:

> too bad they dont use strprefix *yes i will mention this mroe then
> once: P*

It's unnecessary.  strn_cmp(a, b, strlen(b)) checks if b is a prefix of
a.  If you don't like writing that out each time or acknowledging that
this is a lexicographical comparison, go into utils.h and add

  /* strprefix("a", "abc") == TRUE; strprefix("abc", "a") == FALSE */
  #define strprefix(b, a) (strn_cmp((a), (b), strlen((b))) == 0)

This macro can be used as

  if (strprefix(str, "immortal")) {
    /* str is a case-insensitive prefix of immortal. */
  } else
    /* ... */

Of course, I'm confused, because you apparently are used to a function
named strprefix() that does case-insensitive, whole string matching,
rather than case-insensitive, prefix matching.  I'm not familiar enough
with the Merc-family (whence you migrated, I believe) to say, but I have
difficulty believing someone would name a function strprefix() but have it
do whole string matching.

> strcmp being case sensitive and all

That's what str_cmp() is for.  Also, of course, a strcmp() on just the
cases of all-caps and all-lowers is not sufficient, since there may be
random casing within the string.  E.g., "iMmoRtal".  In any regard, you
should use str_cmp().

> return;

This is unnecessary.  Returning at the end of the function is implicit and
writing "return;" there is confusing clutter.


   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/06/01 PST