chiark / gitweb /
*** empty log message ***
authorjames <james>
Wed, 20 Feb 2008 20:16:07 +0000 (20:16 +0000)
committerjames <james>
Wed, 20 Feb 2008 20:16:07 +0000 (20:16 +0000)
apps/mainloop.c
apps/sympathy.c
src/ansi.c
src/ansi.h
src/html.c
src/prototypes.h
test/test.c

index 3c7d01da7d8088372f8d5014355447a323d77c59..fd8f9821525d0d98b15f316203770e39c5c40122 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.7  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/20 19:44:37  james
  * @@
  *
  * Revision 1.6  2008/02/20 19:44:37  james
  * @@
  *
@@ -419,7 +422,7 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
       if (client_socket)
         socket_pre_select (client_socket, &rfds, &wfds);
 
       if (client_socket)
         socket_pre_select (client_socket, &rfds, &wfds);
 
-      if (ansi)
+      if (ansi && ansi->terminal)
         tty_pre_select (ansi->terminal, &rfds, &wfds);
 
       select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
         tty_pre_select (ansi->terminal, &rfds, &wfds);
 
       select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
@@ -470,15 +473,18 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
       /*any data from the server */
       if (client_socket)
         {
       /*any data from the server */
       if (client_socket)
         {
+         int one_shot;
           if (socket_post_select (client_socket, &rfds, &wfds))
             break;
 
           while (client_socket->msg)
             {
               if (msg_from_server (ansi,client_socket->msg, &c))
           if (socket_post_select (client_socket, &rfds, &wfds))
             break;
 
           while (client_socket->msg)
             {
               if (msg_from_server (ansi,client_socket->msg, &c))
-               break;
+               one_shot++;
+               
               socket_consume_msg (client_socket);
             }
               socket_consume_msg (client_socket);
             }
+               if (one_shot) break;
         }
 
 
         }
 
 
index df351f3e9111f56c40082daeeeb5655cfd2e6937..4ea7bf00e730fd8a81ceda048e4d259295418eae 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.11  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
  * Revision 1.10  2008/02/20 19:44:37  james
  * @@
  *
  * Revision 1.10  2008/02/20 19:44:37  james
  * @@
  *
@@ -468,15 +471,12 @@ main (int argc, char *argv[])
 
       if (oflags['H'])
         {
 
       if (oflags['H'])
         {
-          fatal_moan ("fix a bug in HTML dispatcher before this works");
+         ansi=ansi_new_html(stdout);
         }
       else
         {
         }
       else
         {
-          ansi = (ANSI *) malloc (sizeof (ANSI));
-          memset (ansi, 0, sizeof (ANSI));
-
           terminal_register_handlers ();
           terminal_register_handlers ();
-          ansi->terminal = terminal_open (0, 1);
+         ansi=ansi_new_from_terminal(terminal_open(0,1));
           ansi->reset(ansi, NULL);
         }
     }
           ansi->reset(ansi, NULL);
         }
     }
@@ -499,6 +499,7 @@ main (int argc, char *argv[])
   if (client_socket)
     socket_free (client_socket);
 
   if (client_socket)
     socket_free (client_socket);
 
+  if (!oflags['H'])
   printf ("you have now exited sympathy\n");
   return 0;
 }
   printf ("you have now exited sympathy\n");
   return 0;
 }
index 8d4d640e9b07460d4c76da33f62c70001b96cec2..905866b39643485dac74cbbd36fe96b35de8a7bc 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.26  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
  * Revision 1.25  2008/02/20 19:44:37  james
  * @@
  *
  * Revision 1.25  2008/02/20 19:44:37  james
  * @@
  *
@@ -866,7 +869,7 @@ static void ansi_free(ANSI *a)
 
 }
 
 
 }
 
-ANSI *ansi_new_from_terminal(ANSI *a,TTY *t)
+ANSI *ansi_new_from_terminal(TTY *t)
 {
 ANSI *ret;
 
 {
 ANSI *ret;
 
@@ -879,5 +882,7 @@ ret->update=ansi_update;
 ret->reset=ansi_reset;
 ret->terminal_reset=ansi_terminal_reset;
 ret->close=ansi_free;
 ret->reset=ansi_reset;
 ret->terminal_reset=ansi_terminal_reset;
 ret->close=ansi_free;
+ret->dispatch=ansi_dispatch;
 
 
+return ret;
 }
 }
index b88b329848352b26cd9c252d066202d0d9b30c9b..22c0bcdd14aadf69dfef0e10aceaf4a6c2120d47 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.11  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
  * Revision 1.10  2008/02/20 19:44:37  james
  * @@
  *
  * Revision 1.10  2008/02/20 19:44:37  james
  * @@
  *
@@ -76,8 +79,8 @@ typedef struct ANSI_struct
   int attr;
   int color;
 
   int attr;
   int color;
 
-
   int history_ptr;
   int history_ptr;
+  FILE *file;
 
   int (*dispatch)(struct ANSI_struct *,struct Context_struct *);
   void (*update)(struct ANSI_struct *,struct Context_struct *);
 
   int (*dispatch)(struct ANSI_struct *,struct Context_struct *);
   void (*update)(struct ANSI_struct *,struct Context_struct *);
index db142a901cf4bd36ab82bbe1dcd450e86563e612..6aefce3f300dea2b9213a210e067299e3528aa30 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $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 ***
  *
  * Revision 1.2  2008/02/04 02:05:06  james
  * *** empty log message ***
  *
@@ -20,7 +23,32 @@ static char rcsid[] = "$Id$";
 
 #include "project.h"
 
 
 #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)
 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)
 {
 html_render (FILE * f, CRT_CA c)
 {
+int fg,bg;
+  
   if (c.attr & CRT_ATTR_REVERSE)
     {
   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
     {
     }
   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>");
 
   if (c.attr & CRT_ATTR_UNDERLINE)
     fprintf (f, "<ul>");
@@ -77,7 +112,7 @@ html_render (FILE * f, CRT_CA c)
   fprintf (f, "</td>");
 }
 
   fprintf (f, "</td>");
 }
 
-void
+static void
 html_draw (FILE * f, CRT * c)
 {
   CRT_Pos p;
 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>");
     {
       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]);
         }
         {
           html_render (f, c->screen[o]);
         }
@@ -96,3 +131,33 @@ html_draw (FILE * f, CRT * c)
     }
   fprintf (f, "</table>\n");
 }
     }
   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;
+}
+
+
+
+
index 6dc0ca6a1ee78f1883844d47b37604807cdfcb74..0f717663f58223a7d04203879edca948bd2b33de 100644 (file)
@@ -1,6 +1,6 @@
 /* ansi.c */
 extern int ansi_dispatch(ANSI *a, Context *c);
 /* ansi.c */
 extern int ansi_dispatch(ANSI *a, Context *c);
-extern ANSI *ansi_new_from_terminal(ANSI *a, TTY *t);
+extern ANSI *ansi_new_from_terminal(TTY *t);
 /* crt.c */
 extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
 extern void crt_cls(CRT *c);
 /* crt.c */
 extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
 extern void crt_cls(CRT *c);
@@ -9,9 +9,7 @@ extern void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
 extern void crt_reset(CRT *c);
 extern void crt_insert(CRT *c, CRT_CA ca);
 /* html.c */
 extern void crt_reset(CRT *c);
 extern void crt_insert(CRT *c, CRT_CA ca);
 /* html.c */
-extern void html_entity(FILE *f, int c);
-extern void html_render(FILE *f, CRT_CA c);
-extern void html_draw(FILE *f, CRT *c);
+extern ANSI *ansi_new_html(FILE *f);
 /* libsympathy.c */
 /* render.c */
 /* version.c */
 /* libsympathy.c */
 /* render.c */
 /* version.c */
index 8cb6be13751e84f8610bc6d5260e8894e79db235..597a61eb7633304a7f3c57ccb09c15e572deb8c1 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.7  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/15 23:52:12  james
  * *** empty log message ***
  *
  * Revision 1.6  2008/02/15 23:52:12  james
  * *** empty log message ***
  *
@@ -46,6 +49,7 @@ static char rcsid[] =
 int
 main (int argc, char *argv[])
 {
 int
 main (int argc, char *argv[])
 {
+#if 0
   fd_set rfds, wfds;
   ANSI a = { 0 };
   Context c;
   fd_set rfds, wfds;
   ANSI a = { 0 };
   Context c;
@@ -89,4 +93,6 @@ main (int argc, char *argv[])
   ansi_terminal_reset (&a);
   terminal_atexit ();
   printf ("QUAT\n");
   ansi_terminal_reset (&a);
   terminal_atexit ();
   printf ("QUAT\n");
+#endif
+return 0;
 }
 }