chiark / gitweb /
Remove build products
[sympathy.git] / src / html.c
index 5b79219affdb16c45e4460d603c665841321865d..a255bb0047e869582da684a2f3934047dde9ef06 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/* 
  * html.c:
  *
  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
@@ -6,10 +6,40 @@
  *
  */
 
-static char rcsid[] = "$Id$";
+static char rcsid[] = "$Id: html.c,v 1.15 2008/03/07 13:16:02 james Exp $";
 
-/*
- * $Log$
+/* 
+ * $Log: html.c,v $
+ * Revision 1.15  2008/03/07 13:16:02  james
+ * *** empty log message ***
+ *
+ * Revision 1.14  2008/03/07 12:37:04  james
+ * *** empty log message ***
+ *
+ * Revision 1.13  2008/03/06 16:49:39  james
+ * *** empty log message ***
+ *
+ * Revision 1.12  2008/03/06 16:49:05  james
+ * *** empty log message ***
+ *
+ * Revision 1.11  2008/03/03 06:04:42  james
+ * *** empty log message ***
+ *
+ * Revision 1.10  2008/03/02 10:37:56  james
+ * *** empty log message ***
+ *
+ * Revision 1.9  2008/02/27 09:42:22  james
+ * *** empty log message ***
+ *
+ * Revision 1.8  2008/02/27 01:52:38  james
+ * *** empty log message ***
+ *
+ * Revision 1.7  2008/02/27 01:52:08  james
+ * *** empty log message ***
+ *
+ * Revision 1.6  2008/02/20 23:42:05  staffcvs
+ * *** empty log message ***
+ *
  * Revision 1.5  2008/02/20 23:31:48  staffcvs
  * *** empty log message ***
  *
@@ -56,23 +86,29 @@ static int colormap[] = {
 static void
 html_entity (FILE * f, int c)
 {
-  switch (c)
-    {
-    case 32:
-      fprintf (f, "&nbsp;");
-      break;
-    case 38:
-      fprintf (f, "&amp;");
-      break;
-    case 60:
-      fprintf (f, "&lt;");
-      break;
-    case 62:
-      fprintf (f, "&gt;");
-      break;
-    default:
+  switch (c) {
+  case 32:
+    fprintf (f, "&nbsp;");
+    break;
+  case 38:
+    fprintf (f, "&amp;");
+    break;
+  case 60:
+    fprintf (f, "&lt;");
+    break;
+  case 62:
+    fprintf (f, "&gt;");
+    break;
+  default:
+
+    if ((c >= 32) && (c < 127)) {
       fputc (c, f);
+    } else if (c > 127) {
+      fprintf (f, "&#x%04x;", c);
+    } else {
+      fputc (' ', f);
     }
+  }
 }
 
 static void
@@ -80,27 +116,22 @@ html_render (FILE * f, CRT_CA c)
 {
   int fg, bg;
 
-  if (c.attr & CRT_ATTR_REVERSE)
-    {
-      fg = CRT_COLOR_BG (c.color);
-      bg = CRT_COLOR_FG (c.color);
-    }
-  else
-    {
-      fg = CRT_COLOR_FG (c.color);
-      bg = CRT_COLOR_BG (c.color);
-      if (c.attr & CRT_ATTR_BOLD)
-        fg |= CRT_COLOR_INTENSITY;
-    }
-#if 1
+  if (c.attr & CRT_ATTR_REVERSE) {
+    fg = CRT_COLOR_BG (c.color);
+    bg = CRT_COLOR_FG (c.color);
+  } else {
+    fg = CRT_COLOR_FG (c.color);
+    bg = CRT_COLOR_BG (c.color);
+    if (c.attr & CRT_ATTR_BOLD)
+      fg |= CRT_COLOR_INTENSITY;
+  }
+#ifdef CSS
+  fprintf (f, "<span style='color: #%06x; background-color: #%06x'>",
+           colormap[fg], colormap[bg]);
+#else
   fprintf (f, "<td bgcolor='#%06x'><font color='#%06x'>", colormap[bg],
            colormap[fg]);
-#endif
-
   fprintf (f, "<tt>");
-#if 0
-  fprintf (f, "<span style='color: #%06x; background-color: #%06x'>",
-           colormap[fg], colormap[bg]);
 #endif
 
   if (c.attr & CRT_ATTR_UNDERLINE)
@@ -108,28 +139,21 @@ html_render (FILE * f, CRT_CA c)
   if (c.attr & CRT_ATTR_BOLD)
     fprintf (f, "<b>");
 
-  if (c.chr < 32)
-    c.chr = 32;
-  if (c.chr > 126)
-    c.chr = 32;
-
   html_entity (f, c.chr);
 
   if (c.attr & CRT_ATTR_BOLD)
     fprintf (f, "</b>");
   if (c.attr & CRT_ATTR_UNDERLINE)
     fprintf (f, "</ul>");
-  if (c.attr & CRT_ATTR_REVERSE)
-    {
-      fprintf (f, "</font>");
-    }
+  if (c.attr & CRT_ATTR_REVERSE) {
+    fprintf (f, "</font>");
+  }
+#ifdef CSS
+  fprintf (f, "</span>");
+#else
   fprintf (f, "</tt>");
-#if 1
   fprintf (f, "</td>");
 #endif
-#if 0
-  fprintf (f, "</span>");
-#endif
 }
 
 static void
@@ -138,28 +162,38 @@ html_draw (FILE * f, CRT * c)
   CRT_Pos p;
   int o;
 
-// fprintf (f, "<pre>");
+#ifdef CSS
+  fprintf (f, "<pre>");
+#else
   fprintf (f, "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
-  for (p.y = 0; p.y < CRT_ROWS; ++p.y)
-    {
-      o = CRT_ADDR (p.y, 0);
-      fprintf (f, "<tr>");
-      for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o)
-        {
-          html_render (f, c->screen[o]);
-        }
-      fprintf (f, "</tr>\n");
-// fprintf(f,"\n");
+#endif
+  for (p.y = 0; p.y < c->size.y; ++p.y) {
+    o = CRT_ADDR (p.y, 0);
+#ifndef CSS
+    fprintf (f, "<tr>");
+#endif
+    for (p.x = 0; p.x < c->size.x; ++p.x, ++o) {
+      html_render (f, c->screen[o]);
     }
+#ifdef CSS
+    fprintf (f, "\n");
+#else
+    fprintf (f, "</tr>\n");
+#endif
+  }
+#ifdef CSS
+  fprintf (f, "</pre>\n");
+#else
   fprintf (f, "</table>");
-//  fprintf (f, "</pre>\n");
+#endif
 }
 
 
-static void
+static int
 html_one_shot (ANSI * a, CRT * c)
 {
   html_draw (a->file, c);
+  return 0;
 }
 
 
@@ -174,7 +208,7 @@ ansi_new_html (FILE * f)
 {
   ANSI *ret;
 
-  ret = malloc (sizeof (ANSI));
+  ret = xmalloc (sizeof (ANSI));
   memset (ret, 0, sizeof (ANSI));
 
   ret->file = f;