Update to Easy Color v2.2

From: Tony Robbins (tonyr@pacific101.com)
Date: 05/23/99


I noticed a couple things I wanted changed in Easy Color, and I thought you
all might want to peruse it.

Basically, I added redundancy checking (so that it wouldn't use the same color
string repeatedly in a row), and ported a strlen_color() function I got from
some ROM snippet site.  It works for both forms of Easy Color.  Here are the
functions involved, they simply replace the old ones included in color.c:

/* Updated by Tony Robbins to check that we don't repeat the last color,
 * which thus shortens the output and decreases the likelihood of a buffer
 * overflow.                                                      [990523]
 */
void proc_color(char *inbuf, int colour)
{
  register int j = 0, p = 0;
  int k, max, c = 0, last_color = -1;
  char out_buf[32768];

  if (inbuf[0] == '\0')
    return;

  while (inbuf[j] != '\0') {
    if ((inbuf[j]=='\\') && (inbuf[j+1]=='c')
        && isnum(inbuf[j + 2]) && isnum(inbuf[j + 3])) {
      c = (inbuf[j + 2] - '0')*10 + inbuf[j + 3]-'0';
      j += 4;
    } else if ((inbuf[j] == '&') && !(is_colour(inbuf[j + 1]) == -1)) {
      c = is_colour(inbuf[j + 1]);
      j += 2;
    } else {
      out_buf[p] = inbuf[j];
      j++;
      p++;
      continue;
    }
    if (c > MAX_COLORS)
      c = 0;
    max = strlen(COLOURLIST[c]);
    if (colour || max == 1)
      for (k = 0; k < max; k++) {
        if (c != last_color)
          out_buf[p] = COLOURLIST[c][k];
        p++;
      }
  }

  out_buf[p] = '\0';

  strcpy(inbuf, out_buf);
}


/*
 * This is a modified version of a function written by Wreck.
 * Original at http://dark.nrg.dtu.dk/~wreck/mud/code/color.txt
 * [broken link]
 *
 * With the modifications, it should be compatible with the newest
 * version of Lope's colour code.
 *
 * Note: I haven't tested this.  It may not work perfectly.
 *                                              Dennis Reed
 *
 * Converted to CircleMUD/EasyColor v2.2 by Tony Robbins.  I haven't
 * tested it that much either.                              [990523]
 */
int strlen_color(char *argument)
{
  char *str;
  int length = 0, current = 0;

  if (!*argument)
    return (0);

  str = argument;

  while ( str[current] != '\0' )
  {
    if ((str[current] == '\\') && (str[current+1] == 'c') &&
                isnum(str[current+2]) && isnum(str[current+3])) {
      current += 4;
      continue;
    } else if ((str[current] == '&') && !(is_colour(str[current+1]) == -1)) {
      current += 2;
      continue;
    } else {
      current++;
      length++;
      continue;
    }
  }

  return (length);
}


     +------------------------------------------------------------+
     | 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