aboutsummaryrefslogtreecommitdiffstats
path: root/src/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/html.c')
-rw-r--r--src/html.c77
1 files changed, 71 insertions, 6 deletions
diff --git a/src/html.c b/src/html.c
index db142a9..6aefce3 100644
--- a/src/html.c
+++ b/src/html.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/02/20 20:16:07 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/04 02:05:06 james
* *** empty log message ***
*
@@ -20,7 +23,32 @@ static char rcsid[] = "$Id$";
#include "project.h"
-void
+
+#define V(i) (((i)==0)?0x80:(((i)==1)?0xc0:0xff))
+#define COLOR(r,g,b,i) ((((r)?(V(i)):0) << 0)| (((g)?(V(i)):0) << 8)| (((b)?(V(i)):0) << 16))
+
+static int colormap[]=
+{
+[CRT_COLOR_BLACK]=COLOR(0,0,0,0),
+[CRT_COLOR_RED]=COLOR(0,0,1,0),
+[CRT_COLOR_GREEN]=COLOR(0,1,0,0),
+[CRT_COLOR_YELLOW]=COLOR(0,1,1,0),
+[CRT_COLOR_BLUE]=COLOR(1,0,0,0),
+[CRT_COLOR_MAGENTA]=COLOR(1,0,1,0),
+[CRT_COLOR_CYAN]=COLOR(1,1,0,0),
+[CRT_COLOR_WHITE]=COLOR(1,1,1,1),
+[CRT_COLOR_BLACK|CRT_COLOR_INTENSITY]=COLOR(1,1,1,0),
+[CRT_COLOR_RED|CRT_COLOR_INTENSITY]=COLOR(0,0,1,2),
+[CRT_COLOR_GREEN|CRT_COLOR_INTENSITY]=COLOR(0,1,0,2),
+[CRT_COLOR_YELLOW|CRT_COLOR_INTENSITY]=COLOR(0,1,1,2),
+[CRT_COLOR_BLUE|CRT_COLOR_INTENSITY]=COLOR(1,0,0,2),
+[CRT_COLOR_MAGENTA|CRT_COLOR_INTENSITY]=COLOR(1,0,1,2),
+[CRT_COLOR_CYAN|CRT_COLOR_INTENSITY]=COLOR(1,1,0,2),
+[CRT_COLOR_WHITE|CRT_COLOR_INTENSITY]=COLOR(1,1,1,2),
+};
+
+
+static void
html_entity (FILE * f, int c)
{
switch (c)
@@ -42,17 +70,24 @@ html_entity (FILE * f, int c)
}
}
-void
+static void
html_render (FILE * f, CRT_CA c)
{
+int fg,bg;
+
if (c.attr & CRT_ATTR_REVERSE)
{
- fprintf (f, "<td bgcolor='#000000'><font color='#ffffff'>");
+ fg=CRT_COLOR_BG(c.color);
+ bg=CRT_COLOR_FG(c.color);
}
else
{
- fprintf (f, "<td>");
+ fg=CRT_COLOR_FG(c.color);
+ bg=CRT_COLOR_BG(c.color);
+ if (c.attr & CRT_ATTR_BOLD)
+ fg|=CRT_COLOR_INTENSITY;
}
+ fprintf (f, "<td bgcolor='#%06x'><font color='#%06x'>",colormap[bg],colormap[fg]);
if (c.attr & CRT_ATTR_UNDERLINE)
fprintf (f, "<ul>");
@@ -77,7 +112,7 @@ html_render (FILE * f, CRT_CA c)
fprintf (f, "</td>");
}
-void
+static void
html_draw (FILE * f, CRT * c)
{
CRT_Pos p;
@@ -88,7 +123,7 @@ html_draw (FILE * f, CRT * c)
{
o = CRT_ADDR (p.y, 0);
fprintf (f, "<tr>");
- for (p.x = 0; p.x < CRT_ROWS; ++p.x, ++o)
+ for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o)
{
html_render (f, c->screen[o]);
}
@@ -96,3 +131,33 @@ html_draw (FILE * f, CRT * c)
}
fprintf (f, "</table>\n");
}
+
+
+static void html_one_shot(ANSI *a,CRT *c)
+{
+html_draw(a->file,c);
+}
+
+
+static void ansi_free(ANSI *a)
+{
+free(a);
+}
+
+ANSI *ansi_new_html(FILE *f)
+{
+ANSI *ret;
+
+ret=malloc(sizeof(ANSI));
+memset(ret,0,sizeof(ANSI));
+
+ret->file=f;
+ret->close=ansi_free;
+ret->one_shot=html_one_shot;
+
+return ret;
+}
+
+
+
+