for those who asked

From: Wheel of Fish! (piraeus@connectus.com)
Date: 03/16/95


here is a reposting of the color parser for those who asked/missed it:

first we make some changes/additions to utils.h.. add the following at the
top whereever you want to place it.

#define colorcode(x) ( (x>=64 && x<=127) ? de_col[x-64] : 0 ) 

char de_col[] =
{                               /* Not beautiful, but efficient :) */
  0, 0, '4', '6',
  0, 0, 0, '2',
  0, 0, 0, 0,
  '0', '5', 0, 0,
  0, 0, '1', 0,
  0, 0, 0, '7',
  0, '3', 0, 0,
  0, 0, 0, 0,
  0, 0, '4', '6',
  0, 0, 0, '2',
  0, 0, 0, 0,
  '0', '5', 0, 0,
  0, 0, '1', 0,
  0, 0, 0, '7',
  0, '3', 0, 0,
  0, 0, 0, 0,
};

then we add this function down at the bottom (don't forget to prototype it
*grin*)

char *fix_color (struct char_data *ch, unsigned char *src)
{

char *dest;
static char str5[LARGE_BUFSIZE + GARBAGE_SPACE];
int flash = 0;
int changed = 0;
dest = str5;

  while (*src != 0) {
      if (*src != '&') {
	  *dest++ = *src++;
      } else {
        if (*(src + 1) == '*') {
          flash = 1;
          src++;
        }
	  switch (*(src + 1)) {
	    case '&':
	      src += 2;
	      *dest++ = '&';
	      continue;

	    case '+':
		changed = 1;
	      if (colorcode (*(src + 2))) {
		  if (clr(ch, 1)) {
                    if (flash) {
			flash = 0;
                      strcpy((char *) dest, "\033[1;5;30m");
		      dest[7] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 9;
                    } else {
                      strcpy ((char *) dest, "\033[1;30m");
		      dest[5] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 7;
                    }
		  }
		  src += 3;
		  continue;
 	      } else {
		  *dest++ = *src++;
		  continue;
	      }
	    case '-':
		changed = 1;
	      if (colorcode (*(src + 2))) {
		  if (clr(ch, 1)) {
                    if (flash) {
			flash = 0;
                      strcpy((char *) dest, "\033[1;40m");
		      dest[5] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 9;
                    } else {
		      strcpy ((char *) dest, "\033[1;0;40m");
		      dest[7] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 7;
		    }
		  }
		  src += 3;
		  continue;
	      } else {
		  *dest++ = *src++;
		  continue;
	      }
	    case '=':
		changed = 1;
	      if (colorcode (*(src + 2)) && colorcode (*(src + 3))) {
		  if (clr(ch, 1)) {
                    if (flash) {
			flash = 0;
                      strcpy((char *) dest, "\033[1;5;40;30m");
		      dest[7] = colorcode (*(src + 3));
		      dest[9] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 12;
                    } else {
		      strcpy ((char *) dest, "\033[1;40;30m");
		      dest[5] = colorcode (*(src + 3));
		      dest[8] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 10;
		    }
		  }
		  src += 4;
		  continue;
	      } else {
		  *dest++ = *src++;
		  continue;
              }

	    default:
	      *dest++ = *src++;
	      continue;
	    }
	}
    }
   if(changed == 1)
     strcpy ((char *) dest, "\033[0m\0");
   else
     strcpy((char *) dest, "\0");
     
   return(str5);
}


then we make some changes in comm.c in void process_output.. the
added/changed lines are marked with a +

int process_output(struct descriptor_data * t)
{
  static char i[LARGE_BUFSIZE + GARBAGE_SPACE];
  static int result;
+  extern char *fix_color(struct char_data *ch, char *src);
+  char *col2;

+  col2 = fix_color(t->character, t->output);
  
  /* we may need this \r\n for later -- see below */
  strcpy(i, "\r\n");

  /* now, append the 'real' output */
+  strcpy(i + 2, col2);


thats it.. then you use the & in your text (gossip/gecho/etc.. or in your
room descrips and what have you.)

the following letters represent colors, lowercase is standard color,
UPPERcase is BOLD color, &+ is color, &- is highlighted, &=## is set
foreground/background where the # is a letter. placeing a * after the & and
before the following character will create blinking colors.

(r)ed
(y)ellow
(c)yan
(b)lue
(g)reen
(w)hite
(m)agenta
(l)black/grey

note.. a lowercase white is the same as normal text.



This archive was generated by hypermail 2b30 : 12/07/00 PST