I don't see anywhere that you're allocating dynamic memory..
You shouldn't really be using any perms here, much less losing them.
Make sure in the version of strip_color on your mud, you're not calling
str_dup (which was in the function I originally posted).
One thing I noticed, buf should be defined as a 'static char' in strip_color
since you're returning a pointer to it. Basically, buf right now is freed
when the function returns and could be overwritten by who knows what.
Making it static means the memory stays allocated between calls to the
function.
> I am having a slight problem though, or at least I think it's a problem.
> I am noticing a big increase in perms since I added this code ... the
> only place I use this code is in the is_name function which I know is
> called a ton of places. Here is my is_name function with the
> strip_color calls in it.
>
> bool is_name(char *str, char *namelist)
> {
> char name[MAX_INPUT_LENGTH], part[MAX_INPUT_LENGTH];
> char *list, *string;
>
> /* fix crash on NULL namelist */
> if (namelist == NULL || namelist[0] == '\0')
> return FALSE;
>
> /* fixed to prevent is_name on "" returning TRUE */
> if (str[0] == '\0')
> return FALSE;
>
> string = strip_color(str);
> /* we need ALL parts of string to match part of namelist */
> for (;;)
> {
> /* start parsing string */
> str = one_argument(str, part);
>
> if (part[0] == '\0')
> return TRUE;
>
> /* check to see if this is part of namelist */
> list = strip_color(namelist);
> for (;;)
> {
> /* start parsing namelist */
> list = one_argument(list, name);
> if (name[0] == '\0') /* this name was not found */
> return FALSE;
>
> if (!str_prefix(string, name))
> return TRUE; /* full pattern match */
>
> if (!str_prefix(part, name))
> break;
> }
> }
> }
>
> I apologize for the length of this e-mail, but can anyone clue me in as
> to why I would be receiving an increase in perms due to these functions?
>
> Thanks in advance,
> Matt Bradbury
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bobby
> Hicks
> Sent: Monday, January 13, 2003 10:46 PM
> To: 'Hiddukel'; [email protected]
> Subject: RE: stripping colors
>
> This is actually pretty easy. If you are using the colour snippet by
> Lope, you take the string, and step through it till you find a {, or
> what ever ur colour code is, and skip the next character, and keep on
> building.
> IE
> {DThis {Gis {Ba {Gsample {Ystring{C.{x
>
> You input this into *input. Then you check input
> if input++ == '{' { input++; output++ = input++; } else { output++ =
> input++; }
>
> Which, all of that is inside of a for loop, of course. Just make sure
> you look for the '/0' at the end of the string so u can break out of the
> for loop.
>
> Hope this helps out in helping you create your own colour stripper.
>
> Rheede
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> > Of Hiddukel
> > Sent: Monday, January 13, 2003 2:39 AM
> > To: [email protected]
> > Subject: stripping colors
> >
> >
> > I have searched everywhere and can't find a snippet that has
> > a function for stripping color codes from a string and
> > returning the stripped version of the string. Can anyone
> > help me out with some code for this? I'm using lopes colour
> > codes so they are in the format {g etc.. Any help on this
> > would be much appreciated.
> >
> > Matt Bradbury
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom