4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id: html.c,v 1.15 2008/03/07 13:16:02 james Exp $";
13 * Revision 1.15 2008/03/07 13:16:02 james
14 * *** empty log message ***
16 * Revision 1.14 2008/03/07 12:37:04 james
17 * *** empty log message ***
19 * Revision 1.13 2008/03/06 16:49:39 james
20 * *** empty log message ***
22 * Revision 1.12 2008/03/06 16:49:05 james
23 * *** empty log message ***
25 * Revision 1.11 2008/03/03 06:04:42 james
26 * *** empty log message ***
28 * Revision 1.10 2008/03/02 10:37:56 james
29 * *** empty log message ***
31 * Revision 1.9 2008/02/27 09:42:22 james
32 * *** empty log message ***
34 * Revision 1.8 2008/02/27 01:52:38 james
35 * *** empty log message ***
37 * Revision 1.7 2008/02/27 01:52:08 james
38 * *** empty log message ***
40 * Revision 1.6 2008/02/20 23:42:05 staffcvs
41 * *** empty log message ***
43 * Revision 1.5 2008/02/20 23:31:48 staffcvs
44 * *** empty log message ***
46 * Revision 1.4 2008/02/20 22:54:22 staffcvs
47 * *** empty log message ***
49 * Revision 1.3 2008/02/20 20:16:07 james
50 * *** empty log message ***
52 * Revision 1.2 2008/02/04 02:05:06 james
53 * *** empty log message ***
55 * Revision 1.1 2008/02/03 23:31:25 james
56 * *** empty log message ***
63 #define V(i) (((i)==0)?0x80:(((i)==1)?0xc0:0xff))
64 #define COLOR(r,g,b,i) ((((r)?(V(i)):0) << 0)| (((g)?(V(i)):0) << 8)| (((b)?(V(i)):0) << 16))
66 static int colormap[] = {
67 [CRT_COLOR_BLACK] = COLOR (0, 0, 0, 0),
68 [CRT_COLOR_RED] = COLOR (0, 0, 1, 0),
69 [CRT_COLOR_GREEN] = COLOR (0, 1, 0, 0),
70 [CRT_COLOR_YELLOW] = COLOR (0, 1, 1, 0),
71 [CRT_COLOR_BLUE] = COLOR (1, 0, 0, 0),
72 [CRT_COLOR_MAGENTA] = COLOR (1, 0, 1, 0),
73 [CRT_COLOR_CYAN] = COLOR (1, 1, 0, 0),
74 [CRT_COLOR_WHITE] = COLOR (1, 1, 1, 1),
75 [CRT_COLOR_BLACK | CRT_COLOR_INTENSITY] = COLOR (1, 1, 1, 0),
76 [CRT_COLOR_RED | CRT_COLOR_INTENSITY] = COLOR (0, 0, 1, 2),
77 [CRT_COLOR_GREEN | CRT_COLOR_INTENSITY] = COLOR (0, 1, 0, 2),
78 [CRT_COLOR_YELLOW | CRT_COLOR_INTENSITY] = COLOR (0, 1, 1, 2),
79 [CRT_COLOR_BLUE | CRT_COLOR_INTENSITY] = COLOR (1, 0, 0, 2),
80 [CRT_COLOR_MAGENTA | CRT_COLOR_INTENSITY] = COLOR (1, 0, 1, 2),
81 [CRT_COLOR_CYAN | CRT_COLOR_INTENSITY] = COLOR (1, 1, 0, 2),
82 [CRT_COLOR_WHITE | CRT_COLOR_INTENSITY] = COLOR (1, 1, 1, 2),
87 html_entity (FILE * f, int c)
91 fprintf (f, " ");
104 if ((c >= 32) && (c < 127)) {
106 } else if (c > 127) {
107 fprintf (f, "&#x%04x;", c);
115 html_render (FILE * f, CRT_CA c)
119 if (c.attr & CRT_ATTR_REVERSE) {
120 fg = CRT_COLOR_BG (c.color);
121 bg = CRT_COLOR_FG (c.color);
123 fg = CRT_COLOR_FG (c.color);
124 bg = CRT_COLOR_BG (c.color);
125 if (c.attr & CRT_ATTR_BOLD)
126 fg |= CRT_COLOR_INTENSITY;
129 fprintf (f, "<span style='color: #%06x; background-color: #%06x'>",
130 colormap[fg], colormap[bg]);
132 fprintf (f, "<td bgcolor='#%06x'><font color='#%06x'>", colormap[bg],
137 if (c.attr & CRT_ATTR_UNDERLINE)
139 if (c.attr & CRT_ATTR_BOLD)
142 html_entity (f, c.chr);
144 if (c.attr & CRT_ATTR_BOLD)
146 if (c.attr & CRT_ATTR_UNDERLINE)
147 fprintf (f, "</ul>");
148 if (c.attr & CRT_ATTR_REVERSE) {
149 fprintf (f, "</font>");
152 fprintf (f, "</span>");
154 fprintf (f, "</tt>");
155 fprintf (f, "</td>");
160 html_draw (FILE * f, CRT * c)
166 fprintf (f, "<pre>");
168 fprintf (f, "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
170 for (p.y = 0; p.y < c->size.y; ++p.y) {
171 o = CRT_ADDR (p.y, 0);
175 for (p.x = 0; p.x < c->size.x; ++p.x, ++o) {
176 html_render (f, c->screen[o]);
181 fprintf (f, "</tr>\n");
185 fprintf (f, "</pre>\n");
187 fprintf (f, "</table>");
193 html_one_shot (ANSI * a, CRT * c)
195 html_draw (a->file, c);
207 ansi_new_html (FILE * f)
211 ret = xmalloc (sizeof (ANSI));
212 memset (ret, 0, sizeof (ANSI));
215 ret->close = ansi_free;
216 ret->one_shot = html_one_shot;