4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.3 2008/02/20 20:16:07 james
14 * *** empty log message ***
16 * Revision 1.2 2008/02/04 02:05:06 james
17 * *** empty log message ***
19 * Revision 1.1 2008/02/03 23:31:25 james
20 * *** empty log message ***
27 #define V(i) (((i)==0)?0x80:(((i)==1)?0xc0:0xff))
28 #define COLOR(r,g,b,i) ((((r)?(V(i)):0) << 0)| (((g)?(V(i)):0) << 8)| (((b)?(V(i)):0) << 16))
30 static int colormap[]=
32 [CRT_COLOR_BLACK]=COLOR(0,0,0,0),
33 [CRT_COLOR_RED]=COLOR(0,0,1,0),
34 [CRT_COLOR_GREEN]=COLOR(0,1,0,0),
35 [CRT_COLOR_YELLOW]=COLOR(0,1,1,0),
36 [CRT_COLOR_BLUE]=COLOR(1,0,0,0),
37 [CRT_COLOR_MAGENTA]=COLOR(1,0,1,0),
38 [CRT_COLOR_CYAN]=COLOR(1,1,0,0),
39 [CRT_COLOR_WHITE]=COLOR(1,1,1,1),
40 [CRT_COLOR_BLACK|CRT_COLOR_INTENSITY]=COLOR(1,1,1,0),
41 [CRT_COLOR_RED|CRT_COLOR_INTENSITY]=COLOR(0,0,1,2),
42 [CRT_COLOR_GREEN|CRT_COLOR_INTENSITY]=COLOR(0,1,0,2),
43 [CRT_COLOR_YELLOW|CRT_COLOR_INTENSITY]=COLOR(0,1,1,2),
44 [CRT_COLOR_BLUE|CRT_COLOR_INTENSITY]=COLOR(1,0,0,2),
45 [CRT_COLOR_MAGENTA|CRT_COLOR_INTENSITY]=COLOR(1,0,1,2),
46 [CRT_COLOR_CYAN|CRT_COLOR_INTENSITY]=COLOR(1,1,0,2),
47 [CRT_COLOR_WHITE|CRT_COLOR_INTENSITY]=COLOR(1,1,1,2),
52 html_entity (FILE * f, int c)
57 fprintf (f, " ");
74 html_render (FILE * f, CRT_CA c)
78 if (c.attr & CRT_ATTR_REVERSE)
80 fg=CRT_COLOR_BG(c.color);
81 bg=CRT_COLOR_FG(c.color);
85 fg=CRT_COLOR_FG(c.color);
86 bg=CRT_COLOR_BG(c.color);
87 if (c.attr & CRT_ATTR_BOLD)
88 fg|=CRT_COLOR_INTENSITY;
90 fprintf (f, "<td bgcolor='#%06x'><font color='#%06x'>",colormap[bg],colormap[fg]);
92 if (c.attr & CRT_ATTR_UNDERLINE)
94 if (c.attr & CRT_ATTR_BOLD)
102 html_entity (f, c.chr);
104 if (c.attr & CRT_ATTR_BOLD)
106 if (c.attr & CRT_ATTR_UNDERLINE)
107 fprintf (f, "</ul>");
108 if (c.attr & CRT_ATTR_REVERSE)
110 fprintf (f, "</font>");
112 fprintf (f, "</td>");
116 html_draw (FILE * f, CRT * c)
121 fprintf (f, "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
122 for (p.y = 0; p.y < CRT_ROWS; ++p.y)
124 o = CRT_ADDR (p.y, 0);
126 for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o)
128 html_render (f, c->screen[o]);
130 fprintf (f, "</tr>\n");
132 fprintf (f, "</table>\n");
136 static void html_one_shot(ANSI *a,CRT *c)
138 html_draw(a->file,c);
142 static void ansi_free(ANSI *a)
147 ANSI *ansi_new_html(FILE *f)
151 ret=malloc(sizeof(ANSI));
152 memset(ret,0,sizeof(ANSI));
155 ret->close=ansi_free;
156 ret->one_shot=html_one_shot;