Re: [NEWBIE] Managing who2html AND Colorcodes

From: Daniel A. Koepke (dkoepke@california.com)
Date: 12/24/99


On Fri, 24 Dec 1999, Nick Stout wrote:

> I have a MUD that is currently running on the Color Codes 2.2... You
> know... The "&<letter>" ones. =)

If the patch doesn't include a function or other method for stripping
color codes (I suspect it does, you'd have to look, though; dread the day
someone actually RTFC), then it's really trivial to write a routine to do
such, like this one (Mailer Code(tm)),

    char *
    strip_ampersand_codes (const char *str)
    {
        static char retval[MAX_STRING_LENGTH+1];
        register char *ptr;
        int space_left;

        space_left = MAX_STRING_LENGTH;

        for ( ptr = retval; space_left > 0 && *str; str++ ) {
            if ( *str == '&' ) {
                if ( *(++str) == '&' )
                    *(ptr++) = '&';
            } else *(ptr++) = *str;
        }

        *ptr = '\0';
        return (retval);
    }

> I'm pretty sure I understand the color code system, but I'm not sure I
> know how to either get rid of the symbols with their corresponding
> letter, or parse it using HTML color instead of ANSI.

If you want to replace them with HTML color sequences, it's a bit more
tricky.  Maybe something like:

    char *
    parse_colors_html (const char *str)
    {
        static char retval[MAX_STRING_LENGTH*2 + 1];
        register char *ptr, *tag;
        int space_left;

        space_left = MAX_STRING_LENGTH*2;

        for ( ptr = retval; *str; str++ ) {
            if ( *str == '&' ) {
                switch ( *(++str) ) {
                    case 'k': tag = "<font color=\"#000000\">"; break;
                    case 'K': tag = "<font color=\"#555555\">"; break;
                    case 'r': tag = "<font color=\"#880000\">"; break;
                    case 'R': tag = "<font color=\"#FF0000\">"; break;
                    case 'g': tag = "<font color=\"#008800\">"; break;
                    case 'G': tag = "<font color=\"#00FF00\">"; break;
                    .
                    .
                    .
                }

                while ( (*(ptr++) = *(tag++)) )
                    ;
            } else
                *(ptr++) = *str;
        }

        *ptr = '\0';
        return (retval);
    }

This latter can actually be achieved by just copying the color code
parser, stripping out the unnecessary parts, and instead of putting in
\x1B[...m just put in <font color="...">.  That's up to you.

-dak


     +------------------------------------------------------------+
     | 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 : 12/15/00 PST