4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.4 2008/02/20 22:54:22 staffcvs
14 * *** empty log message ***
16 * Revision 1.3 2008/02/20 20:16:07 james
17 * *** empty log message ***
19 * Revision 1.2 2008/02/04 02:05:06 james
20 * *** empty log message ***
22 * Revision 1.1 2008/02/03 23:31:25 james
23 * *** empty log message ***
30 #define V(i) (((i)==0)?0x80:(((i)==1)?0xc0:0xff))
31 #define COLOR(r,g,b,i) ((((r)?(V(i)):0) << 0)| (((g)?(V(i)):0) << 8)| (((b)?(V(i)):0) << 16))
33 static int colormap[] = {
34 [CRT_COLOR_BLACK] = COLOR (0, 0, 0, 0),
35 [CRT_COLOR_RED] = COLOR (0, 0, 1, 0),
36 [CRT_COLOR_GREEN] = COLOR (0, 1, 0, 0),
37 [CRT_COLOR_YELLOW] = COLOR (0, 1, 1, 0),
38 [CRT_COLOR_BLUE] = COLOR (1, 0, 0, 0),
39 [CRT_COLOR_MAGENTA] = COLOR (1, 0, 1, 0),
40 [CRT_COLOR_CYAN] = COLOR (1, 1, 0, 0),
41 [CRT_COLOR_WHITE] = COLOR (1, 1, 1, 1),
42 [CRT_COLOR_BLACK | CRT_COLOR_INTENSITY] = COLOR (1, 1, 1, 0),
43 [CRT_COLOR_RED | CRT_COLOR_INTENSITY] = COLOR (0, 0, 1, 2),
44 [CRT_COLOR_GREEN | CRT_COLOR_INTENSITY] = COLOR (0, 1, 0, 2),
45 [CRT_COLOR_YELLOW | CRT_COLOR_INTENSITY] = COLOR (0, 1, 1, 2),
46 [CRT_COLOR_BLUE | CRT_COLOR_INTENSITY] = COLOR (1, 0, 0, 2),
47 [CRT_COLOR_MAGENTA | CRT_COLOR_INTENSITY] = COLOR (1, 0, 1, 2),
48 [CRT_COLOR_CYAN | CRT_COLOR_INTENSITY] = COLOR (1, 1, 0, 2),
49 [CRT_COLOR_WHITE | CRT_COLOR_INTENSITY] = COLOR (1, 1, 1, 2),
54 html_entity (FILE * f, int c)
59 fprintf (f, " ");
76 html_render (FILE * f, CRT_CA c)
80 if (c.attr & CRT_ATTR_REVERSE)
82 fg = CRT_COLOR_BG (c.color);
83 bg = CRT_COLOR_FG (c.color);
87 fg = CRT_COLOR_FG (c.color);
88 bg = CRT_COLOR_BG (c.color);
89 if (c.attr & CRT_ATTR_BOLD)
90 fg |= CRT_COLOR_INTENSITY;
92 fprintf (f, "<td bgcolor='#%06x'><font color='#%06x'>", colormap[bg],
95 if (c.attr & CRT_ATTR_UNDERLINE)
97 if (c.attr & CRT_ATTR_BOLD)
105 html_entity (f, c.chr);
107 if (c.attr & CRT_ATTR_BOLD)
109 if (c.attr & CRT_ATTR_UNDERLINE)
110 fprintf (f, "</ul>");
111 if (c.attr & CRT_ATTR_REVERSE)
113 fprintf (f, "</font>");
115 fprintf (f, "</td>");
119 html_draw (FILE * f, CRT * c)
124 fprintf (f, "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
125 for (p.y = 0; p.y < CRT_ROWS; ++p.y)
127 o = CRT_ADDR (p.y, 0);
129 for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o)
131 html_render (f, c->screen[o]);
133 fprintf (f, "</tr>\n");
135 fprintf (f, "</table>\n");
140 html_one_shot (ANSI * a, CRT * c)
142 html_draw (a->file, c);
153 ansi_new_html (FILE * f)
157 ret = malloc (sizeof (ANSI));
158 memset (ret, 0, sizeof (ANSI));
161 ret->close = ansi_free;
162 ret->one_shot = html_one_shot;