eod/
eod/changes/
eod/log/
eod/player/
eod/player/backup/
eod/player/store/
/* convert.c
 *
 * This file contains two functions, where ansi_to_html()
 * is the one used by you, and the other append_html_color()
 * is a support function used by ansi_to_html(). Please
 * add all the colors you want ansi_to_html() to be able
 * to convert to html tags. A few examples has been given.
 */

#define MAX_BUFFER      4096  /* size of the parse buffer          */
#define HTML_SIZE         21  /* length of <font color=\"??????\"> */

/* local procudures */
char *ansi_to_html       ( const char *str );
void  append_html_color  ( char *buf, char *colorcode );

int main()
{
  const char *ansi_string = "#R=== #YKobold #R===#n";

  printf("%s\n", ansi_to_html(ansi_string));

  return;
}

char *ansi_to_html(const char *str)
{
  static char buf[MAX_BUFFER] = { '\0' };
  char *ptr = buf;

  while(*str != '\0')
  {
    switch(*str)
    {
      default:
        *ptr++ = *str++;
        break;
      case '#':
        switch(*(++str))
        {
          default:
            *ptr++ = '#';
            break;
          case 'R':
            append_html_color(ptr, "FF0000");
            ptr += HTML_SIZE;
            str++;
            break;
          case 'Y':
            append_html_color(ptr, "FFFF00");
            ptr += HTML_SIZE;
            str++;
            break;
          case 'n':
            append_html_color(ptr, "FFFFFF");
            ptr += HTML_SIZE;
            str++;
            break;
        }
        break;
    }
  }
  *ptr = '\0';

  return buf;
}

void append_html_color(char *buf, char *colorcode)
{
  if (strlen(colorcode) != 6)
  {
    // eeep, did something nasty...
    return;
  }

  buf[0]  = '<';  buf[1]  = 'f';  buf[2]  = 'o';  buf[3]  = 'n';
  buf[4]  = 't';  buf[5]  = ' ';  buf[6]  = 'c';  buf[7]  = 'o';
  buf[8]  = 'l';  buf[9]  = 'o';  buf[10] = 'r';  buf[11] = '=';
  buf[12] = '\"';

  buf[13] = colorcode[0]; buf[14] = colorcode[1]; buf[15] = colorcode[2];
  buf[16] = colorcode[3]; buf[17] = colorcode[4]; buf[18] = colorcode[5];

  buf[19]  = '\"';  buf[20]  = '>';
}