Ansi color

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


the following is a fixed version of the color parser.. I still don't have a
& code for return to normal but I'll get that as soon as possible.. until
then.. this fixed version will stop the flashies when you change to another
& code.. (ie. &*+rbahaha &+rbahahah) will give you flashing red bahaha and
then a standard NON-flashing red bahaha

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[0m\033[1;30m");
		      dest[9] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[6] = '0';
		      dest += 11;
                    }
		  }
		  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;5;40m");
		      dest[7] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 9;
                    } else {
		      strcpy ((char *) dest, "\033[0m\033[1;40m");
		      dest[9] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[6] = '0';
		      dest += 11;
		    }
		  }
		  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[10] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[2] = '0';
		      dest += 12;
                    } else {
		      strcpy ((char *) dest, "\033[0m\033[1;40;30m");
		      dest[9] = colorcode (*(src + 3));
		      dest[12] = colorcode (*(src + 2));
		      if (*(src + 2) >= 96)
			dest[6] = '0';
		      dest += 14;
		    }
		  }
		  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);
}



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