Re: [CODE] CAP/UPPER???

From: Mysidia (jmhess@i-55.com)
Date: 07/21/00


On Fri, 21 Jul 2000, Patrick Vale wrote:

> In our mud color codes have been changed to &g &s ..etc. The problem arises that
> mobs with short descripts beginning with color codes are no longer automatically
> capitalized or such when they walk out of rooms hit things etc.
> I figure this is because the code works with the '&' symbol we are using? 'Cap'
> is a macro for 'upper' function i think? I cannot find where in the code (i
> have looked lots and lots) it changes things to upper/lower case so i can make
> it ignore our color codes.
> Any help greatly appreciated...am i on the right track? (newbie)...:)
> Have a fabulous day, Ladak *legends of toril* (aka patrick)
CAP() is located in utils.h
the line reads: #define CAP(st) (*(st) = UPPER(*st), st)

#define CAP(st) ((((*st!='&'||!isalnum(st[1]))?1:0) ? *(st) = UPPER(*st) \
                 : *(st + 1) = UPPER(*(st + 1))), st)
...

   Is the best way I can think of to deal with a problem like that
offhand while keeping the same general usage as CAP has currently, CAP
is used quite often, so the overhead of converting it to a function would be
significant -- well I suppose if your compiler supports it, it might be
just as effective to use an inlined function..

...

ex:
[top of utils.h]
extern char * str_cap(char *);
[in place of CAP]
#define CAP(x) (char *)str_cap((x));
[bottom of utils.c or something]

#if defined(__GNUC__)
inline char *str_cap(char * pt)
#else
char *str_cap(char * pt)
#endif
{
   char *orig = pt; /* Temp hold start location of string */

   if (!pt || *pt != '&') /* Trap nullptr, non-color, or 0-length quickly */
       return !pt ? pt : (*(pt) = UPPER(*pt), pt);

   /* Skip leading color sequences */
   for (;*pt == '&' && isalnum(*(pt + 1)); pt += 2);

   /* Raise the first non-color-code found in case, return held start loc */
   return (*(pt) = UPPER(*pt), orig);
}

...

-Mysid


     +------------------------------------------------------------+
     | 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 : 04/10/01 PDT