Add this function to utils.c:
char *cap_color(char *buf)
{
int i = 0;
while (buf[i]) {
if (buf[i] == '&') {
i+= 2;
continue;
} else if ((UPPER(buf[i]) >= 'A') && (UPPER(buf[i]) <= 'Z')) {
buf[i] = UPPER(buf[i]);
break;
}
i++;
}
return (buf);
}
Then replace function calls to CAP with this function wherever you feel that
color may come into play. This function could be written using pointers
instead to be faster, but I just whipped this up for you real quick. As
always, you need to make sure that you do not use your prototype strings in
calls to CAP or cap_color since it will change every occurrence of that
string.
Rick
-----Original Message-----
From: Mysidia [mailto:jmhess@I-55.COM]
Sent: Friday, July 21, 2000 6:59 AM
To: CIRCLE@post.queensu.ca
Subject: Re: [CIRCLE] [CODE] CAP/UPPER???
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 |
+------------------------------------------------------------+
+------------------------------------------------------------+
| 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