chiark / gitweb /
*** empty log message ***
authorjames <james>
Wed, 13 Feb 2008 09:12:20 +0000 (09:12 +0000)
committerjames <james>
Wed, 13 Feb 2008 09:12:20 +0000 (09:12 +0000)
13 files changed:
src/Makefile.am
src/ansi.c
src/context.h
src/crt.h
src/libsympathy.c
src/project.h
src/prototypes.h
src/ptty.c
src/ring.c
src/terminal.c
src/tty.h
src/util.c
src/vt102.c

index 94f0f7b2b45eb69d2645ea551fa340b94eb20163..968d9deb8e1e091885968185076a504fe5a7a5f5 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
 # $Id$
 #
 # $Log$
+# Revision 1.8  2008/02/13 09:12:20  james
+# *** empty log message ***
+#
 # Revision 1.7  2008/02/12 22:36:46  james
 # *** empty log message ***
 #
 # Revision 1.7  2008/02/12 22:36:46  james
 # *** empty log message ***
 #
@@ -39,7 +42,7 @@ HDRS=ansi.h context.h crt.h history.h keys.h project.h prototypes.h \
        ring.h sympathy.h tty.h vt102.h
 
 SRCS=ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c \
        ring.h sympathy.h tty.h vt102.h
 
 SRCS=ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c \
-       history.c ring.c ptty.c
+       history.c ring.c ptty.c terminal.c util.c
 
 CPROTO=cproto
 
 
 CPROTO=cproto
 
index b6f30f9c45762df7c7ab22738a8f3063103ce629..12a0563f8f494790113187e0661f3f54b54a3286 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.18  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.17  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
  * Revision 1.17  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
@@ -64,24 +67,6 @@ static char rcsid[] = "$Id$";
  */
 #include "project.h"
 
  */
 #include "project.h"
 
-static void
-set_nonblocking (int fd)
-{
-  long arg;
-  arg = fcntl (fd, F_GETFL, arg);
-  arg |= O_NONBLOCK;
-  fcntl (fd, F_SETFL, arg);
-}
-
-static void
-set_blocking (int fd)
-{
-  long arg;
-  arg = fcntl (fd, F_GETFL, arg);
-  arg &= ~O_NONBLOCK;
-  fcntl (fd, F_SETFL, arg);
-}
-
 
 void
 ansi_move (ANSI * a, CRT_Pos p)
 
 void
 ansi_move (ANSI * a, CRT_Pos p)
@@ -431,7 +416,26 @@ ansi_draw (ANSI * a, CRT * c)
   int o;
   int hidden_cursor = 0;
 
   int o;
   int hidden_cursor = 0;
 
-  if (crt_pos_cmp(a->terminal.size,a->size)) {
+  if (crt_pos_cmp (a->terminal->size, a->size))
+    {
+      terminal_getsize (a->terminal);
+
+      a->size = a->terminal->size;
+
+      a->pos.x = ANSI_INVAL;
+      a->hide_cursor = ANSI_INVAL;
+
+      crt_reset (&a->crt);
+
+// FIXME: -- echos back crap?
+//  a->terminal->xmit (a->terminal, "\033[c", 3);
+
+      ansi_cls (a);
+      a->terminal->xmit (a->terminal, "\033=", 2);
+      a->terminal->xmit (a->terminal, "\033[?6l", 5);
+      a->terminal->xmit (a->terminal, "\033[r", 3);
+
+    }
 
 
   for (p.y = 0; p.y < CRT_ROWS; ++p.y)
 
 
   for (p.y = 0; p.y < CRT_ROWS; ++p.y)
@@ -487,34 +491,19 @@ ansi_draw (ANSI * a, CRT * c)
 void
 ansi_reset (ANSI * a)
 {
 void
 ansi_reset (ANSI * a)
 {
-// FIXME: -- echos back crap?
-//  a->terminal->xmit (a->terminal, "\033[c", 3);
-
-  terminal_getsize(a->terminal);
-
-  a->size=a->terminal->size;
-
-  a->pos.x = ANSI_INVAL;
-  a->hide_cursor = ANSI_INVAL;
-
-  crt_reset (&a->crt);
-
-  ansi_cls (a);
-  a->terminal->xmit (a->terminal, "\033=", 2);
-  a->terminal->xmit (a->terminal, "\033[?6l", 5);
-  a->terminal->xmit (a->terminal, "\033[r", 3);
+  a->size.x = -1;
   ansi_draw (a, &a->crt);
 }
 
 void
   ansi_draw (a, &a->crt);
 }
 
 void
-ansi_flush_escape (ANSI * a, Context *c)
+ansi_flush_escape (ANSI * a, Context * c)
 {
   ANSI_Parser *p = &a->parser;
   int i;
 
   for (i = 0; i < p->escape_ptr; ++i)
     {
 {
   ANSI_Parser *p = &a->parser;
   int i;
 
   for (i = 0; i < p->escape_ptr; ++i)
     {
-      vt102_send (c->v, p->escape_buf[i], c->t);
+      vt102_send (c, p->escape_buf[i]);
     }
 
   p->escape_ptr = 0;
     }
 
   p->escape_ptr = 0;
@@ -522,7 +511,7 @@ ansi_flush_escape (ANSI * a, Context *c)
 }
 
 void
 }
 
 void
-ansi_parse_deckey (ANSI * a, Context *c)
+ansi_parse_deckey (ANSI * a, Context * c)
 {
   ANSI_Parser *p = &a->parser;
   if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O'))
 {
   ANSI_Parser *p = &a->parser;
   if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O'))
@@ -533,15 +522,15 @@ ansi_parse_deckey (ANSI * a, Context *c)
 
   if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
     {
 
   if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
     {
-      vt102_send (c->v, KEY_UP + (p->escape_buf[2] - 'A'), c->t);
+      vt102_send (c, KEY_UP + (p->escape_buf[2] - 'A'));
     }
   else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
     {
     }
   else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
     {
-      vt102_send (c->v, KEY_154 + (p->escape_buf[2] - 'a'), c->t);
+      vt102_send (c, KEY_154 + (p->escape_buf[2] - 'a'));
     }
   else
     {
     }
   else
     {
-      ansi_flush_escape (a,c);
+      ansi_flush_escape (a, c);
       return;
     }
   p->in_escape = 0;
       return;
     }
   p->in_escape = 0;
@@ -549,7 +538,7 @@ ansi_parse_deckey (ANSI * a, Context *c)
 }
 
 void
 }
 
 void
-ansi_parse_ansikey (ANSI * a,Context *c)
+ansi_parse_ansikey (ANSI * a, Context * c)
 {
   ANSI_Parser *p = &a->parser;
 
 {
   ANSI_Parser *p = &a->parser;
 
@@ -560,11 +549,11 @@ ansi_parse_ansikey (ANSI * a,Context *c)
     }
   if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
     {
     }
   if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
     {
-      vt102_send (c->v, KEY_180 + (p->escape_buf[2] - '0'), c->t);
+      vt102_send (c, KEY_180 + (p->escape_buf[2] - '0'));
     }
   else
     {
     }
   else
     {
-      ansi_flush_escape (a,c);
+      ansi_flush_escape (a, c);
       return;
     }
 
       return;
     }
 
@@ -575,7 +564,7 @@ ansi_parse_ansikey (ANSI * a,Context *c)
 
 
 void
 
 
 void
-ansi_parse_escape (ANSI * a,Context *c)
+ansi_parse_escape (ANSI * a, Context * c)
 {
   ANSI_Parser *p = &a->parser;
   switch (p->escape_ptr)
 {
   ANSI_Parser *p = &a->parser;
   switch (p->escape_ptr)
@@ -590,7 +579,7 @@ ansi_parse_escape (ANSI * a,Context *c)
         case 'O':
           break;
         default:
         case 'O':
           break;
         default:
-          ansi_flush_escape (a,c);
+          ansi_flush_escape (a, c);
         }
       break;
     case 3:
         }
       break;
     case 3:
@@ -601,10 +590,10 @@ ansi_parse_escape (ANSI * a,Context *c)
           break;
         case '[':
           if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z'))
           break;
         case '[':
           if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z'))
-            ansi_parse_deckey (a,c);
+            ansi_parse_deckey (a, c);
           break;
         default:
           break;
         default:
-          ansi_flush_escape (a,c);
+          ansi_flush_escape (a, c);
         }
       break;
     case 4:
         }
       break;
     case 4:
@@ -614,17 +603,17 @@ ansi_parse_escape (ANSI * a,Context *c)
           ansi_parse_ansikey (a, c);
           break;
         default:
           ansi_parse_ansikey (a, c);
           break;
         default:
-          ansi_flush_escape (a,c);
+          ansi_flush_escape (a, c);
         }
       break;
     case 5:
         }
       break;
     case 5:
-      ansi_flush_escape (a,c);
+      ansi_flush_escape (a, c);
     }
 }
 
 
 void
     }
 }
 
 
 void
-ansi_check_escape (ANSI * a, Context *c)
+ansi_check_escape (ANSI * a, Context * c)
 {
   ANSI_Parser *p = &a->parser;
   struct timeval now, diff;
 {
   ANSI_Parser *p = &a->parser;
   struct timeval now, diff;
@@ -642,13 +631,13 @@ ansi_check_escape (ANSI * a, Context *c)
 
   /*Time up? */
   if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
 
   /*Time up? */
   if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
-    ansi_flush_escape (a,c);
+    ansi_flush_escape (a, c);
 
 }
 
 
 void
 
 }
 
 
 void
-ansi_parse_char (ANSI * a,Context *c, int ch)
+ansi_parse_char (ANSI * a, Context * c, int ch)
 {
   ANSI_Parser *p = &a->parser;
 
 {
   ANSI_Parser *p = &a->parser;
 
@@ -659,7 +648,7 @@ ansi_parse_char (ANSI * a,Context *c, int ch)
   if (ch == 033)
     {
       if (p->in_escape)
   if (ch == 033)
     {
       if (p->in_escape)
-        ansi_flush_escape (a,c);
+        ansi_flush_escape (a, c);
 
       p->in_escape++;
       p->escape_ptr = 0;
 
       p->in_escape++;
       p->escape_ptr = 0;
@@ -669,32 +658,31 @@ ansi_parse_char (ANSI * a,Context *c, int ch)
   if (p->in_escape)
     {
       p->escape_buf[p->escape_ptr++] = ch;
   if (p->in_escape)
     {
       p->escape_buf[p->escape_ptr++] = ch;
-      ansi_parse_escape (a,c);
+      ansi_parse_escape (a, c);
     }
   else
     {
     }
   else
     {
-      vt102_send (c->v, ch, c->t);
+      vt102_send (c, ch);
     }
 
 }
 
 void
     }
 
 }
 
 void
-ansi_parse (ANSI * a,Context *c, char *buf, int len)
+ansi_parse (ANSI * a, Context * c, char *buf, int len)
 {
   while (len--)
 {
   while (len--)
-    ansi_parse_char (a,c, *(buf++));
+    ansi_parse_char (a, c, *(buf++));
 }
 
 int
 }
 
 int
-ansi_dispatch (ANSI * a, Context *c)
+ansi_dispatch (ANSI * a, Context * c)
 {
   char buf[1024];
   int red;
 
   ansi_check_escape (a, c);
 
 {
   char buf[1024];
   int red;
 
   ansi_check_escape (a, c);
 
-
-  red = a->terminal->recv(a->terminal,buf,sizeof(buf));
+  red = a->terminal->recv (a->terminal, buf, sizeof (buf));
   if (red <= 0)
     return red;
 
   if (red <= 0)
     return red;
 
@@ -709,7 +697,7 @@ ansi_dispatch (ANSI * a, Context *c)
 #endif
 
 
 #endif
 
 
-  ansi_parse (a,c, buf, red );
+  ansi_parse (a, c, buf, red);
 
   return 0;
 }
 
   return 0;
 }
index 607f24969f7fcc5fc2c3d4ba127e6786b49aa86a..c2b7798f4597faa04ed33acb9688dd680abf9dd8 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
@@ -28,6 +31,7 @@ typedef struct
   VT102 *v;
   TTY *t;
   History *h;
   VT102 *v;
   TTY *t;
   History *h;
+  Log *l;
 } Context;
 
 #endif /* __CONTEXT_H__ */
 } Context;
 
 #endif /* __CONTEXT_H__ */
index addaed8a90bd89d772e58f8a32d4fc6a7513e186..410b390ff9e75eda4475eb63486d01b2f00aff14 100644 (file)
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.8  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.7  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
  * Revision 1.7  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
@@ -115,7 +118,7 @@ crt_ca_cmp (CRT_CA a, CRT_CA b)
 }
 
 static inline
 }
 
 static inline
-crt_pos_cmp (CRT_POS a, CRT_POS b)
+crt_pos_cmp (CRT_Pos a, CRT_Pos b)
 {
   return memcmp (&a, &b, sizeof (a));
 }
 {
   return memcmp (&a, &b, sizeof (a));
 }
index 7e6d78beedae5d6f8f84f50dc24354500653487c..989b664a7f433596a3823cae2214275cc827c4f2 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.16  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.15  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
  * Revision 1.15  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
@@ -66,12 +69,12 @@ static char rcsid[] =
 void
 testy (void)
 {
 void
 testy (void)
 {
+  fd_set rfd;
   struct termios raw = { 0 };
   ANSI a = { 0 };
   Context c;
 
 #if 0
   struct termios raw = { 0 };
   ANSI a = { 0 };
   Context c;
 
 #if 0
-  fd_set rfd;
   int fd;
   char c;
 
   int fd;
   char c;
 
@@ -81,15 +84,18 @@ testy (void)
   int i;
 #endif
 
   int i;
 #endif
 
-  
+
 
   ansi_reset (&a);
 
 
 
   ansi_reset (&a);
 
 
-  c.t = tty_new_test ();
+  c.t = ptty_open (NULL, NULL);
   c.v = vt102_new ();
   c.v = vt102_new ();
+  c.h = history_new (200);
+  c.l = NULL;
 
 
-  a.terminal=terminal_open(0,1);
+  terminal_register_handlers ();
+  a.terminal = terminal_open (0, 1);
 
 
   FD_ZERO (&rfd);
 
 
   FD_ZERO (&rfd);
@@ -97,33 +103,21 @@ testy (void)
     {
       struct timeval tv = { 0, 100000 };
 
     {
       struct timeval tv = { 0, 100000 };
 
-      FD_SET (t->fd, &rfd);
-      FD_SET (a.fd, &rfd);
-      select (t->fd + 1, &rfd, NULL, NULL, &tv);
 
 
-#if 0
-      if (FD_ISSET (a.fd, &rfd))
-        {
-        }
-#endif
+      FD_SET (c.t->rfd, &rfd);
+      FD_SET (a.terminal->rfd, &rfd);
 
 
-      switch (ansi_dispatch (&a, v, t))
-        {
-        case -1:
-          break;
-        case 1:
-          ansi_getsize (&a);
-          ansi_reset (&a);
-          ansi_draw (&a, &v->crt);
-          break;
-        }
+      select (FD_SETSIZE, &rfd, NULL, NULL, &tv);
 
 
-      if (FD_ISSET (t->fd, &rfd))
+      ansi_dispatch (&a, &c);
+
+      if (FD_ISSET (c.t->rfd, &rfd))
         {
         {
-          if (vt102_dispatch_one (v, t, h))
+          if (vt102_dispatch (&c))
             break;
         }
 
             break;
         }
 
+#if 0
       if (had_winch)
         {
           had_winch = 0;
       if (had_winch)
         {
           had_winch = 0;
@@ -131,8 +125,10 @@ testy (void)
           ansi_reset (&a);
           ansi_draw (&a, &v->crt);
         }
           ansi_reset (&a);
           ansi_draw (&a, &v->crt);
         }
-      ansi_draw (&a, &v->crt);
+#endif
+      //FIXME history
+      ansi_draw (&a, &c.v->crt);
     }
     }
-  tcsetattr (0, TCSANOW, &old);
-  printf ("QUAT\n");
+
+  terminal_atexit ();
 }
 }
index 9de6b17cfb6ff8fd440732cb69e3a76bf91a41cb..ed331238bb2b7af1ef3919ea7afbf36d1ba3fe8c 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.7  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/09 15:47:28  james
  * *** empty log message ***
  *
  * Revision 1.6  2008/02/09 15:47:28  james
  * *** empty log message ***
  *
 #include <utmp.h>
 #include <pty.h>
 
 #include <utmp.h>
 #include <pty.h>
 
-#include "tty.h"
 #include "crt.h"
 #include "crt.h"
+#include "tty.h"
 #include "ansi.h"
 #include "vt102.h"
 #include "keys.h"
 #include "history.h"
 #include "ring.h"
 #include "ansi.h"
 #include "vt102.h"
 #include "keys.h"
 #include "history.h"
 #include "ring.h"
+#include "log.h"
 
 #include "context.h"
 
 
 #include "context.h"
 
index 17027e123f5e72435ee3c80f7190771be910816f..f1f07421664b6528ef4f2d5e6d235c322fa336f0 100644 (file)
@@ -1,83 +1,93 @@
 /* ansi.c */
 /* ansi.c */
-void ansi_move(ANSI *a, CRT_Pos p);
-void ansi_showhide_cursor(ANSI *a, int hide);
-void ansi_force_attr_normal(ANSI *a);
-void ansi_set_color(ANSI *a, int color);
-void ansi_set_attr(ANSI *a, int attr);
-void ansi_render(ANSI *a, CRT_CA ca);
-void ansi_cls(ANSI *a);
-int ansi_scroll_up(ANSI *a, CRT_Pos s, CRT_Pos e);
-void ansi_spot_scroll_up(ANSI *a, CRT *c);
-void ansi_spot_scroll(ANSI *a, CRT *c);
-void ansi_draw(ANSI *a, CRT *c);
-void ansi_reset(ANSI *a);
-void ansi_flush_escape(ANSI *a, Context *c);
-void ansi_parse_deckey(ANSI *a, Context *c);
-void ansi_parse_ansikey(ANSI *a, Context *c);
-void ansi_parse_escape(ANSI *a, Context *c);
-void ansi_check_escape(ANSI *a, Context *c);
-void ansi_parse_char(ANSI *a, Context *c, int ch);
-void ansi_parse(ANSI *a, Context *c, char *buf, int len);
-int ansi_dispatch(ANSI *a, Context *c);
+void ansi_move (ANSI * a, CRT_Pos p);
+void ansi_showhide_cursor (ANSI * a, int hide);
+void ansi_force_attr_normal (ANSI * a);
+void ansi_set_color (ANSI * a, int color);
+void ansi_set_attr (ANSI * a, int attr);
+void ansi_render (ANSI * a, CRT_CA ca);
+void ansi_cls (ANSI * a);
+void ansi_draw (ANSI * a, CRT * c);
+void ansi_reset (ANSI * a);
+void ansi_flush_escape (ANSI * a, Context * c);
+void ansi_parse_deckey (ANSI * a, Context * c);
+void ansi_parse_ansikey (ANSI * a, Context * c);
+void ansi_parse_escape (ANSI * a, Context * c);
+void ansi_check_escape (ANSI * a, Context * c);
+void ansi_parse_char (ANSI * a, Context * c, int ch);
+void ansi_parse (ANSI * a, Context * c, char *buf, int len);
+int ansi_dispatch (ANSI * a, Context * c);
 /* crt.c */
 /* crt.c */
-void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
-void crt_cls(CRT *c);
-void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
-void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
-void crt_reset(CRT *c);
-void crt_insert(CRT *c, CRT_CA ca);
+void crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea);
+void crt_cls (CRT * c);
+void crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea);
+void crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea);
+void crt_reset (CRT * c);
+void crt_insert (CRT * c, CRT_CA ca);
 /* html.c */
 /* html.c */
-void html_entity(FILE *f, int c);
-void html_render(FILE *f, CRT_CA c);
-void html_draw(FILE *f, CRT *c);
+void html_entity (FILE * f, int c);
+void html_render (FILE * f, CRT_CA c);
+void html_draw (FILE * f, CRT * c);
 /* libsympathy.c */
 /* libsympathy.c */
-struct termios old;
-void testy(void);
+void testy (void);
 /* render.c */
 /* version.c */
 /* vt102.c */
 /* render.c */
 /* version.c */
 /* vt102.c */
-void vt102_log_line(VT102 *v, int line);
-void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br);
-void vt102_cursor_normalize(VT102 *v);
-void vt102_cursor_carriage_return(VT102 *v);
-void vt102_cursor_advance_line(VT102 *v);
-void vt102_cursor_advance(VT102 *v);
-void vt102_do_pending_wrap(VT102 *v);
-void vt102_cursor_retard(VT102 *v);
-void vt102_reset_tabs(VT102 *v);
-void vt102_cursor_advance_tab(VT102 *v);
-int vt102_cursor_home(VT102 *v);
-int vt102_cursor_absolute(VT102 *v, int x, int y);
-int vt102_cursor_relative(VT102 *v, int x, int y);
-void vt102_delete_from_line(VT102 *v, CRT_Pos p);
-void vt102_insert_into_line(VT102 *v, CRT_Pos p);
-void vt102_change_mode(VT102 *v, int private, char *ns, int set);
-void vt102_parse_mode_string(VT102 *v, char *buf, int len);
-void vt102_change_attr(VT102 *v, char *na);
-void vt102_parse_attr_string(VT102 *v, char *buf, int len);
-void vt102_save_state(VT102 *v);
-void vt102_restore_state(VT102 *v);
-void vt102_scs(VT102 *c, int g, int s);
-void vt102_parse_esc(VT102 *v, int c);
-void vt102_parse_csi(VT102 *v, char *buf, int len);
-void vt102_status_line(VT102 *v, char *str);
-void vt102_parse_char(VT102 *v, int c, TTY *tty);
-int vt102_parse(VT102 *v, char *buf, int len, TTY *t);
-void vt102_parser_reset(VT102_parser *p);
-void vt102_send(VT102 *v, uint8_t key, TTY *tty);
-void vt102_reset(VT102 *v);
-int vt102_dispatch(VT102 *v, TTY *tty);
-int vt102_dispatch_one(VT102 *v, TTY *tty);
-VT102 *vt102_new(void);
-void vt102_free(VT102 *v);
+void vt102_log_line (Context * c, int line);
+void vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br);
+void vt102_cursor_normalize (VT102 * v);
+void vt102_cursor_carriage_return (VT102 * v);
+void vt102_cursor_advance_line (Context * c);
+void vt102_cursor_advance (Context * c);
+void vt102_do_pending_wrap (Context * c);
+void vt102_cursor_retard (VT102 * v);
+void vt102_reset_tabs (VT102 * v);
+void vt102_cursor_advance_tab (VT102 * v);
+int vt102_cursor_home (VT102 * v);
+int vt102_cursor_absolute (VT102 * v, int x, int y);
+int vt102_cursor_relative (VT102 * v, int x, int y);
+void vt102_delete_from_line (VT102 * v, CRT_Pos p);
+void vt102_insert_into_line (VT102 * v, CRT_Pos p);
+void vt102_change_mode (VT102 * v, int private, char *ns, int set);
+void vt102_parse_mode_string (VT102 * v, char *buf, int len);
+void vt102_change_attr (VT102 * v, char *na);
+void vt102_parse_attr_string (VT102 * v, char *buf, int len);
+void vt102_save_state (VT102 * v);
+void vt102_restore_state (VT102 * v);
+void vt102_scs (Context * c, int g, int s);
+void vt102_parse_esc (Context * c, int ch);
+void vt102_parse_csi (Context * c, char *buf, int len);
+void vt102_status_line (VT102 * v, char *str);
+void vt102_parse_char (Context * c, int ch);
+int vt102_parse (Context * c, char *buf, int len);
+void vt102_parser_reset (VT102_parser * p);
+void vt102_send (Context * c, uint8_t key);
+void vt102_reset (VT102 * v);
+int vt102_dispatch (Context * c);
+int vt102_dispatch_one (Context * c);
+VT102 *vt102_new (void);
+void vt102_free (VT102 * v);
 /* tty.c */
 /* history.c */
 /* tty.c */
 /* history.c */
-History *history_new(int n);
-void history_free(History *h);
-void history_add(History *h, CRT_CA *c);
+History *history_new (int n);
+void history_free (History * h);
+void history_add (History * h, CRT_CA * c);
 /* ring.c */
 /* ring.c */
-int ring_read(Ring *r, void *b, int n);
-int ring_write(Ring *r, void *b, int n);
-Ring *ring_new(int n);
+int ring_read (Ring * r, void *b, int n);
+int ring_write (Ring * r, void *b, int n);
+Ring *ring_new (int n);
 /* ptty.c */
 /* ptty.c */
-TTY *ptty_open(char *path, char *argv[]);
+TTY *ptty_open (char *path, char *argv[]);
+/* terminal.c */
+int terminal_winches;
+void terminal_atexit (void);
+void terminal_getsize (TTY * _t);
+void terminal_dispatch (void);
+void terminal_register_handlers (void);
+TTY *terminal_open (int rfd, int wfd);
+/* util.c */
+int wrap_read (int fd, void *buf, int len);
+int wrap_write (int fd, void *buf, int len);
+void set_nonblocking (int fd);
+void set_blocking (int fd);
+void raw_termios (struct termios *termios);
+void default_termios (struct termios *termios);
index b59f823e40f8ebc667aacd8ee2208824ef308de5..c0f85f5689e647e7f1afc8e8a62e1d5c33222dc5 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
@@ -118,14 +121,20 @@ ptty_open (char *path, char *argv[])
   struct winsize winsize = { 0 };
   struct termios termios;
   int fd;
   struct winsize winsize = { 0 };
   struct termios termios;
   int fd;
-  char *default_argv = { "-", (char *) 0 };
+  char *default_argv[] = { "-", (char *) 0 };
+
+
+  default_termios (&termios);
+
+  winsize.ws_row = VT102_ROWS;
+  winsize.ws_col = VT102_COLS;
 
   child = forkpty (&fd, name, &termios, &winsize);
 
   switch (child)
     {
     case -1:                   /*boo hiss */
 
   child = forkpty (&fd, name, &termios, &winsize);
 
   switch (child)
     {
     case -1:                   /*boo hiss */
-      return -1;
+      return NULL;
     case 0:                    /*waaah */
       setenv ("TERM", "vt102", 1);
       setenv ("LANG", "C", 1);
     case 0:                    /*waaah */
       setenv ("TERM", "vt102", 1);
       setenv ("LANG", "C", 1);
@@ -146,19 +155,15 @@ ptty_open (char *path, char *argv[])
   strncpy (t->name, name, sizeof (t->name));
   t->name[sizeof (t->name) - 1] = 0;
 
   strncpy (t->name, name, sizeof (t->name));
   t->name[sizeof (t->name) - 1] = 0;
 
-  t->read = ptty_read;
-  t->write = ptty_write;
+  t->recv = ptty_read;
+  t->xmit = ptty_write;
   t->close = ptty_close;
   t->close = ptty_close;
-
-  default_termios (&termios);
-
-  winsize.ws_row = VT102_ROWS;
-  winsize.ws_col = VT102_COLS;
-
-  t->fd = open_fd_to_pty (path, argv);
-  t->pid = child;
+  t->fd = fd;
+  t->child = child;
   t->rfd = t->fd;
   t->rfd = t->fd;
-  t->wfd = 0;
+  t->wfd = t->fd;
+  t->size.x = winsize.ws_row;
+  t->size.y = winsize.ws_col;
 
   return (TTY *) t;
 }
 
   return (TTY *) t;
 }
index f9ef6af861600260236b25e62cf5d413eec8405f..ccd97edc426f2d281e64ce4f46b09688c30a2148 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
@@ -62,7 +65,7 @@ Ring *
 ring_new (int n)
 {
   Ring *ret = (Ring *) malloc (sizeof (Ring));
 ring_new (int n)
 {
   Ring *ret = (Ring *) malloc (sizeof (Ring));
-  ret->buf = (uint8_t *) malloc (n);
+  ret->ring = (uint8_t *) malloc (n);
   ret->size = n;
   ret->wptr = ret->rptr = 0;
 
   ret->size = n;
   ret->wptr = ret->rptr = 0;
 
index f0472a1ba94dac268c441b328b3be908a9a1fd14..1223c0f0b677d610edca450c99e9ec83baac20af 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
  * Revision 1.2  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
@@ -47,7 +50,7 @@ typedef struct TERMINAL_struct
 } TERMINAL;
 
 
 } TERMINAL;
 
 
-static TERMINAL terminal_list=NULL;
+static TERMINAL *terminal_list = NULL;
 int terminal_winches;
 
 
 int terminal_winches;
 
 
@@ -56,36 +59,39 @@ static void
 terminal_close (TTY * _t)
 {
   TERMINAL *t = (TERMINAL *) _t;
 terminal_close (TTY * _t)
 {
   TERMINAL *t = (TERMINAL *) _t;
-  TERMINAL **ptr=&terminal_list;
+  TERMINAL **ptr = &terminal_list;
 
   if (!t)
     return;
 
   /* Take out of cleanup list */
 
   if (!t)
     return;
 
   /* Take out of cleanup list */
-  while (*ptr && (*ptr != t)) ptr=&((*ptr)->next);
+  while (*ptr && (*ptr != t))
+    ptr = &((*ptr)->next);
 
 
-  if (*ptr) 
-       *ptr=t->next;
+  if (*ptr)
+    *ptr = t->next;
 
 
-  tcsetattr(t->wfd,TCSANOW,&t->orig_termios);
+  tcsetattr (t->wfd, TCSANOW, &t->orig_termios);
 
 
-  set_blocking(t->rfd);
-  set_blocking(t->wfd);
+  set_blocking (t->rfd);
+  set_blocking (t->wfd);
 
   free (t);
 }
 
 
 
   free (t);
 }
 
 
-void terminal_atexit(void)
+void
+terminal_atexit (void)
 {
 {
-while (terminal_list)
-       terminal_close(terminal_list);
+  while (terminal_list)
+    terminal_close ((TTY *) terminal_list);
 }
 
 }
 
-static void sigint(int dummy)
+static void
+sigint (int dummy)
 {
 {
-terminal_atexit();
-exit(-1);
+  terminal_atexit ();
+  exit (-1);
 }
 
 static void
 }
 
 static void
@@ -96,14 +102,15 @@ sigwinch (int not)
 
 
 void
 
 
 void
-terminal_getsize (TTY *_t)
+terminal_getsize (TTY * _t)
 {
 {
-TERMINAL *t=(TTY *) _t;
+  TERMINAL *t = (TERMINAL *) _t;
   struct winsize sz = { 0 };
 
   struct winsize sz = { 0 };
 
-if (!t) return;
+  if (!t)
+    return;
 
 
-if (ioctl (a->wfd, TIOCGWINSZ, &sz))
+  if (ioctl (t->wfd, TIOCGWINSZ, &sz))
     {
       t->size.x = CRT_COLS;
       t->size.y = CRT_ROWS;
     {
       t->size.x = CRT_COLS;
       t->size.y = CRT_ROWS;
@@ -116,17 +123,19 @@ if (ioctl (a->wfd, TIOCGWINSZ, &sz))
 }
 
 
 }
 
 
-void terminal_dispatch(void)
+void
+terminal_dispatch (void)
 {
 {
-TERMINAL *t;
+  TERMINAL *t;
 
 
 
 
-if (!terminal_winches) return;
+  if (!terminal_winches)
+    return;
 
 
-terminal_winches=0;
+  terminal_winches = 0;
 
 
-for (t=terminal_list;t;t=t->next)
-terminal_getsize(t);
+  for (t = terminal_list; t; t = t->next)
+    terminal_getsize (t);
 
 }
 
 
 }
 
@@ -137,12 +146,12 @@ terminal_read (TTY * _t, void *buf, int len)
   TERMINAL *t = (TERMINAL *) _t;
   int red, done = 0;
 
   TERMINAL *t = (TERMINAL *) _t;
   int red, done = 0;
 
-  terminal_dispatch();
+  terminal_dispatch ();
 
   do
     {
 
 
   do
     {
 
-      red = wrap_read (t->fd, buf, len);
+      red = wrap_read (t->rfd, buf, len);
       if (red < 0)
         return -1;
       if (!red)
       if (red < 0)
         return -1;
       if (!red)
@@ -165,12 +174,12 @@ terminal_write (TTY * _t, void *buf, int len)
   int writ, done = 0;
   TERMINAL *t = (TERMINAL *) _t;
 
   int writ, done = 0;
   TERMINAL *t = (TERMINAL *) _t;
 
-  terminal_dispatch();
+  terminal_dispatch ();
 
   do
     {
 
 
   do
     {
 
-      writ = wrap_write (t->fd, buf, len);
+      writ = wrap_write (t->wfd, buf, len);
       if (writ < 0)
         return -1;
       if (!writ)
       if (writ < 0)
         return -1;
       if (!writ)
@@ -187,21 +196,22 @@ terminal_write (TTY * _t, void *buf, int len)
 }
 
 
 }
 
 
-void terminal_register_handlers(void)
+void
+terminal_register_handlers (void)
 {
 {
- struct sigaction sa = { 0 };
 struct sigaction sa = { 0 };
 
 
-    sa.sa_handler = sigwinch;
-    sa.sa_flags = SA_RESTART;
-    sigaction (SIGWINCH, &sa, NULL);
+  sa.sa_handler = sigwinch;
+  sa.sa_flags = SA_RESTART;
+  sigaction (SIGWINCH, &sa, NULL);
 
 
-    sa.sa_handler = sigint;
-    sa.sa_flags = SA_RESTART;
-    sigaction (SIGINT, &sa, NULL);
+  sa.sa_handler = sigint;
+  sa.sa_flags = SA_RESTART;
+  sigaction (SIGINT, &sa, NULL);
 }
 
 TTY *
 }
 
 TTY *
-terminal_open (int rfd,int wfd)
+terminal_open (int rfd, int wfd)
 {
   TERMINAL *t;
   pid_t child;
 {
   TERMINAL *t;
   pid_t child;
@@ -213,12 +223,12 @@ terminal_open (int rfd,int wfd)
   t->rfd = rfd;
   t->wfd = wfd;
 
   t->rfd = rfd;
   t->wfd = wfd;
 
-  tcgetattr(wfd,&t->orig_termios);
+  tcgetattr (wfd, &t->orig_termios);
 
 
-  t->next=terminal_list;
-  terminal_list=t;
+  t->next = terminal_list;
+  terminal_list = t;
 
 
-  tcgetattr(tfd,&termios);
+  tcgetattr (wfd, &termios);
 
   set_nonblocking (rfd);
   set_nonblocking (wfd);
 
   set_nonblocking (rfd);
   set_nonblocking (wfd);
@@ -226,15 +236,14 @@ terminal_open (int rfd,int wfd)
 
   raw_termios (&termios);
 
 
   raw_termios (&termios);
 
-  tcsetattr(wfd,TCSANOW,&termios);
+  tcsetattr (wfd, TCSANOW, &termios);
 
 
-  t->read = terminal_read;
-  t->write = terminal_write;
+  t->recv = terminal_read;
+  t->xmit = terminal_write;
   t->close = terminal_close;
 
 
   t->close = terminal_close;
 
 
-  terminal_getsize((TTY*) t);
+  terminal_getsize ((TTY *) t);
 
   return (TTY *) t;
 }
 
   return (TTY *) t;
 }
-
index 76e2803aede7def04a341ef6972de51a856da2fb..91b14c664b491711d5eb3305b34dc9afae9ab350 100644 (file)
--- a/src/tty.h
+++ b/src/tty.h
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.5  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.4  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
  * Revision 1.4  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
@@ -31,7 +34,7 @@
 
 #define TTY_SIGNATURE \
        char name[1024]; \
 
 #define TTY_SIGNATURE \
        char name[1024]; \
-       CRT_POS size; \
+       CRT_Pos size; \
        void (*close)(struct TTY_struct *); \
        int (*recv)(struct TTY_struct *,void *buf,int len); \
        int (*xmit)(struct TTY_struct *,void *buf,int len); \
        void (*close)(struct TTY_struct *); \
        int (*recv)(struct TTY_struct *,void *buf,int len); \
        int (*xmit)(struct TTY_struct *,void *buf,int len); \
index e8b315ea4725518bfa79df0eea06eba20cfaa8ba..bd838b90a6de5f234a0fe44465dc43ccf358207d 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/13 01:08:38  james
  * *** empty log message ***
  *
  * Revision 1.1  2008/02/13 01:08:38  james
  * *** empty log message ***
  *
@@ -66,7 +69,8 @@ set_blocking (int fd)
   fcntl (fd, F_SETFL, arg);
 }
 
   fcntl (fd, F_SETFL, arg);
 }
 
-void raw_termios(struct termios *termios)
+void
+raw_termios (struct termios *termios)
 {
 
   termios->c_iflag = ICRNL | IXON;
 {
 
   termios->c_iflag = ICRNL | IXON;
@@ -97,12 +101,10 @@ default_termios (struct termios *termios)
 
   memset (termios, 0, sizeof (termios));
 
 
   memset (termios, 0, sizeof (termios));
 
-  raw_termios(termios);
+  raw_termios (termios);
 
   termios->c_cflag = CS8 | CREAD | CLOCAL;
 
   cfsetispeed (termios, B9600);
   cfsetospeed (termios, B9600);
 }
 
   termios->c_cflag = CS8 | CREAD | CLOCAL;
 
   cfsetispeed (termios, B9600);
   cfsetospeed (termios, B9600);
 }
-
-
index f3101bb6ec7a48e666cfbf10e4af1bc74e02b0a2..a8d4388610ccccaa82b16c0c6631784fa8723718 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
 
 /*
  * $Log$
+ * Revision 1.24  2008/02/13 09:12:21  james
+ * *** empty log message ***
+ *
  * Revision 1.23  2008/02/07 13:26:35  james
  * *** empty log message ***
  *
  * Revision 1.23  2008/02/07 13:26:35  james
  * *** empty log message ***
  *
@@ -231,35 +234,34 @@ in_margins (VT102 * v, CRT_Pos p)
 }
 
 void
 }
 
 void
-vt102_log_line (VT102 * v, int line)
+vt102_log_line (Context * c, int line)
 {
 {
-  static FILE *log;
   CRT_Pos e = { VT102_COLS - 1, line };
   CRT_Pos p = { 0, line };
   CRT_Pos e = { VT102_COLS - 1, line };
   CRT_Pos p = { 0, line };
+  char logbuf[VT102_COLS + 1];
 
 
-  if (!log)
-    log = fopen ("log", "a+");
-
-  if (!log)
+  if (!c->l)
     return;
 
 
   for (; e.x > 0; --e.x)
     {
     return;
 
 
   for (; e.x > 0; --e.x)
     {
-      if (v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
+      if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
         break;
     }
 
   for (; p.x <= e.x; ++p.x)
     {
         break;
     }
 
   for (; p.x <= e.x; ++p.x)
     {
-      int c = v->crt.screen[CRT_ADDR_POS (&p)].chr;
-      if (c < 32)
-        c = ' ';
-      if (c > 126)
-        c = ' ';
-      fputc (c, log);
+      int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
+      if (ch < 32)
+        ch = ' ';
+      if (ch > 126)
+        ch = ' ';
+      logbuf[p.x] = ch;
     }
     }
-  fputc ('\n', log);
+  logbuf[p.x] = 0;
+
+  c->l->log (c->l, logbuf);
 }
 
 void
 }
 
 void
@@ -301,8 +303,9 @@ vt102_cursor_carriage_return (VT102 * v)
 }
 
 void
 }
 
 void
-vt102_cursor_advance_line (VT102 * v)
+vt102_cursor_advance_line (Context * c)
 {
 {
+  VT102 *v = c->v;
   int couldscroll = in_margins (v, v->pos);
 
 /*have wraped off end of last line in scrolling region */
   int couldscroll = in_margins (v, v->pos);
 
 /*have wraped off end of last line in scrolling region */
@@ -310,7 +313,8 @@ vt102_cursor_advance_line (VT102 * v)
   if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
       (couldscroll))
     {
   if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
       (couldscroll))
     {
-      vt102_log_line (v, v->pos.y);
+      vt102_log_line (c, v->pos.y);
+      //FIXME call out to history
       crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
       return;
     }
       crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
       return;
     }
@@ -321,8 +325,9 @@ vt102_cursor_advance_line (VT102 * v)
 
 
 void
 
 
 void
-vt102_cursor_advance (VT102 * v)
+vt102_cursor_advance (Context * c)
 {
 {
+  VT102 *v = c->v;
 
   if (v->pos.x < v->bottom_margin.x)
     {
 
   if (v->pos.x < v->bottom_margin.x)
     {
@@ -336,8 +341,9 @@ vt102_cursor_advance (VT102 * v)
 
 
 void
 
 
 void
-vt102_do_pending_wrap (VT102 * v)
+vt102_do_pending_wrap (Context * c)
 {
 {
+  VT102 *v = c->v;
   int couldscroll = in_margins (v, v->pos);
   int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
 
   int couldscroll = in_margins (v, v->pos);
   int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
 
@@ -366,7 +372,7 @@ vt102_do_pending_wrap (VT102 * v)
       v->pos.x = 0;
     }
 
       v->pos.x = 0;
     }
 
-  vt102_cursor_advance_line (v);
+  vt102_cursor_advance_line (c);
 }
 
 
 }
 
 
@@ -755,20 +761,21 @@ vt102_restore_state (VT102 * v)
 }
 
 void
 }
 
 void
-vt102_scs (VT102 * c, int g, int s)
+vt102_scs (Context * c, int g, int s)
 {
 /*Ignoring charsets*/
 }
 
 void
 {
 /*Ignoring charsets*/
 }
 
 void
-vt102_parse_esc (VT102 * v, int c)
+vt102_parse_esc (Context * c, int ch)
 {
 {
-  switch (c)
+  VT102 *v = c->v;
+  switch (ch)
     {
     case 'E':
       if (v->pos.y == v->bottom_margin.y)
         {
     {
     case 'E':
       if (v->pos.y == v->bottom_margin.y)
         {
-          vt102_log_line (v, v->pos.y);
+          vt102_log_line (c, v->pos.y);
           crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
         }
       else
           crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
         }
       else
@@ -803,20 +810,22 @@ vt102_parse_esc (VT102 * v, int c)
       break;
     default:
 #if 0
       break;
     default:
 #if 0
-      fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", c,
-               (c < 32) ? '?' : c);
+      fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", ch,
+               (ch < 32) ? '?' : ch);
 #endif
       ;
     }
 }
 void
 #endif
       ;
     }
 }
 void
-vt102_parse_csi (VT102 * v, char *buf, int len)
+vt102_parse_csi (Context * c, char *buf, int len)
 {
   char last;
   char *ptr;
   char *arg = buf + 1;
   int narg;
 
 {
   char last;
   char *ptr;
   char *arg = buf + 1;
   int narg;
 
+  VT102 *v = c->v;
+
   buf[len] = 0;
 
   last = buf[len - 1];
   buf[len] = 0;
 
   last = buf[len - 1];
@@ -928,7 +937,10 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
               && (v->pos.y <= v->bottom_margin.y))
             {
               while (narg--)
               && (v->pos.y <= v->bottom_margin.y))
             {
               while (narg--)
-                crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
+                {
+                  //FIXME call out to history
+                  crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
+                }
             }
           break;
 
             }
           break;
 
@@ -1024,53 +1036,53 @@ vt102_status_line (VT102 * v, char *str)
 
 
 void
 
 
 void
-vt102_parse_char (VT102 * v, int c, TTY * tty)
+vt102_parse_char (Context * c, int ch)
 {
 {
+  VT102 *v = c->v;
   VT102_parser *p = &v->parser;
 
   VT102_parser *p = &v->parser;
 
-
 #if 0
   fprintf (stderr, "char %c pc %d %d %d   %d %d\n", (c < 32) ? 32 : c, c,
            p->in_csi, p->in_escape, v->pos.x, v->pos.y);
 #endif
   if (p->in_csi)
     {
 #if 0
   fprintf (stderr, "char %c pc %d %d %d   %d %d\n", (c < 32) ? 32 : c, c,
            p->in_csi, p->in_escape, v->pos.x, v->pos.y);
 #endif
   if (p->in_csi)
     {
-      p->csi_buf[p->csi_ptr++] = c;
-      if (csi_ender (c) || (p->csi_ptr == VT102_CSI_LEN))
+      p->csi_buf[p->csi_ptr++] = ch;
+      if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
         {
         {
-          vt102_parse_csi (v, p->csi_buf, p->csi_ptr);
+          vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
           p->in_csi = 0;
         }
     }
   else if (p->in_escape)
     {
           p->in_csi = 0;
         }
     }
   else if (p->in_escape)
     {
-      if (csi_starter (c))
+      if (csi_starter (ch))
         {
           p->csi_ptr = 0;
         {
           p->csi_ptr = 0;
-          p->csi_buf[p->csi_ptr++] = c;
+          p->csi_buf[p->csi_ptr++] = ch;
           p->in_csi++;
           p->in_escape = 0;
         }
           p->in_csi++;
           p->in_escape = 0;
         }
-      else if (scs_starter (c))
+      else if (scs_starter (ch))
         {
         {
-          p->in_scs = c;
+          p->in_scs = ch;
           p->in_escape = 0;
         }
       else
         {
           p->in_escape = 0;
           p->in_escape = 0;
         }
       else
         {
           p->in_escape = 0;
-          vt102_parse_esc (v, c);
+          vt102_parse_esc (c, ch);
         }
     }
   else if (p->in_scs)
     {
         }
     }
   else if (p->in_scs)
     {
-      vt102_scs (v, p->in_scs, c);
+      vt102_scs (c, p->in_scs, ch);
       p->in_scs = 0;
     }
   else
     {
 
       p->in_scs = 0;
     }
   else
     {
 
-      switch (c)
+      switch (ch)
         {
          /*NUL*/ case 0:
          /*SOH*/ case 1:
         {
          /*NUL*/ case 0:
          /*SOH*/ case 1:
@@ -1079,21 +1091,21 @@ vt102_parse_char (VT102 * v, int c, TTY * tty)
          /*EOT*/ case 4:
           break;
          /*ENQ*/ case 5:
          /*EOT*/ case 4:
           break;
          /*ENQ*/ case 5:
-          tty_write (tty, "vt102", 5);
+          c->t->xmit (c->t, "vt102", 5);
           break;
          /*ACK*/ case 6:
          /*BEL*/ case 7:
           break;
          /*BS*/ case 8:
           break;
          /*ACK*/ case 6:
          /*BEL*/ case 7:
           break;
          /*BS*/ case 8:
-          vt102_cursor_retard (v);
+          vt102_cursor_retard (c->v);
           break;
          /*HT*/ case 9:
           break;
          /*HT*/ case 9:
-          vt102_cursor_advance_tab (v);
+          vt102_cursor_advance_tab (c->v);
           break;
          /*LF*/ case 10:
          /*VT*/ case 11:
          /*FF*/ case 12:
           break;
          /*LF*/ case 10:
          /*VT*/ case 11:
          /*FF*/ case 12:
-          vt102_cursor_advance_line (v);
+          vt102_cursor_advance_line (c);
           if (!v->modes[VT102_MODE_NEWLINE_MODE])
             break;
          /*CR*/ case 13:
           if (!v->modes[VT102_MODE_NEWLINE_MODE])
             break;
          /*CR*/ case 13:
@@ -1129,15 +1141,15 @@ vt102_parse_char (VT102 * v, int c, TTY * tty)
          /*DEL*/ case 127:
           break;
         /*regular character */ default:
          /*DEL*/ case 127:
           break;
         /*regular character */ default:
-          vt102_do_pending_wrap (v);
+          vt102_do_pending_wrap (c);
 
           if (v->modes[VT102_MODE_INSERT])
             vt102_insert_into_line (v, v->pos);
 
 
           if (v->modes[VT102_MODE_INSERT])
             vt102_insert_into_line (v, v->pos);
 
-          v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
+          v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
           v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
           v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
           v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
           v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
-          vt102_cursor_advance (v);
+          vt102_cursor_advance (c);
         }
     }
 
         }
     }
 
@@ -1147,17 +1159,17 @@ vt102_parse_char (VT102 * v, int c, TTY * tty)
 
   if (v->current_line.y != v->pos.y)
     {
 
   if (v->current_line.y != v->pos.y)
     {
-      vt102_log_line (v, v->current_line.y);
+      vt102_log_line (c, v->current_line.y);
       v->current_line = v->pos;
     }
 
   vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
 }
 
       v->current_line = v->pos;
     }
 
   vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
 }
 
-vt102_parse (VT102 * v, char *buf, int len, TTY * t)
+vt102_parse (Context * c, char *buf, int len)
 {
   while (len--)
 {
   while (len--)
-    vt102_parse_char (v, *(buf++), t);
+    vt102_parse_char (c, *(buf++));
 }
 
 
 }
 
 
@@ -1172,15 +1184,15 @@ vt102_parser_reset (VT102_parser * p)
 
 
 void
 
 
 void
-vt102_send (VT102 * v, uint8_t key, TTY * tty)
+vt102_send (Context * c, uint8_t key)
 {
 {
-  uint8_t c;
+  uint8_t ch;
 #if 0
   fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
 #endif
   if ((key > 31) && (key < 127))
     {
 #if 0
   fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
 #endif
   if ((key > 31) && (key < 127))
     {
-      tty_write (tty, &key, 1);
+      c->t->xmit (c->t, &key, 1);
       return;
     }
 
       return;
     }
 
@@ -1199,14 +1211,14 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
      /*LF*/ case 10:
      /*VT*/ case 11:
      /*FF*/ case 12:
      /*LF*/ case 10:
      /*VT*/ case 11:
      /*FF*/ case 12:
-      tty_write (tty, &key, 1);
+      c->t->xmit (c->t, &key, 1);
       break;
      /*CR*/ case 13:
       break;
      /*CR*/ case 13:
-      tty_write (tty, &key, 1);
-      if (v->modes[VT102_MODE_NEWLINE_MODE])
+      c->t->xmit (c->t, &key, 1);
+      if (c->v->modes[VT102_MODE_NEWLINE_MODE])
         {
         {
-          c = 10;
-          tty_write (tty, &c, 1);
+          ch = 10;
+          c->t->xmit (c->t, &ch, 1);
         }
       break;
      /*SO*/ case 14:
         }
       break;
      /*SO*/ case 14:
@@ -1222,7 +1234,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
      /*CAN*/ case 24:
      /*EM*/ case 25:
      /*SUB*/ case 26:
      /*CAN*/ case 24:
      /*EM*/ case 25:
      /*SUB*/ case 26:
-      tty_write (tty, &key, 1);
+      c->t->xmit (c->t, &key, 1);
       break;
      /*ESC*/ case 27:
      /*FS*/ case 28:
       break;
      /*ESC*/ case 27:
      /*FS*/ case 28:
@@ -1230,7 +1242,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
      /*RS*/ case 30:
      /*US*/ case 31:
      /*DEL*/ case 127:
      /*RS*/ case 30:
      /*US*/ case 31:
      /*DEL*/ case 127:
-      tty_write (tty, &key, 1);
+      c->t->xmit (c->t, &key, 1);
       break;
 
     case KEY_UP:
       break;
 
     case KEY_UP:
@@ -1241,15 +1253,15 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
     case KEY_MIDDLE:
     case KEY_END:
 
     case KEY_MIDDLE:
     case KEY_END:
 
-      if (v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
+      if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
         {
           uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
         {
           uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
-          tty_write (tty, &buf, sizeof (buf));
+          c->t->xmit (c->t, &buf, sizeof (buf));
         }
       else
         {
           uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
         }
       else
         {
           uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
-          tty_write (tty, &buf, sizeof (buf));
+          c->t->xmit (c->t, &buf, sizeof (buf));
         }
       break;
     case KEY_STAR:
         }
       break;
     case KEY_STAR:
@@ -1267,10 +1279,10 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
     case KEY_7:
     case KEY_8:
     case KEY_9:
     case KEY_7:
     case KEY_8:
     case KEY_9:
-      if (v->application_keypad_mode)
+      if (c->v->application_keypad_mode)
         {
           uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
         {
           uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
-          tty_write (tty, &buf, sizeof (buf));
+          c->t->xmit (c->t, &buf, sizeof (buf));
         }
       else
         {
         }
       else
         {
@@ -1293,23 +1305,23 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
             [KEY_9] = '9'
           };
 
             [KEY_9] = '9'
           };
 
-          tty_write (tty, &kpoff[key], 1);
+          c->t->xmit (c->t, &kpoff[key], 1);
         }
       break;
     case KEY_ENTER:
         }
       break;
     case KEY_ENTER:
-      if (v->application_keypad_mode)
+      if (c->v->application_keypad_mode)
         {
           uint8_t buf[] = { 033, 'O', 'M' };
         {
           uint8_t buf[] = { 033, 'O', 'M' };
-          tty_write (tty, &buf, sizeof (buf));
+          c->t->xmit (c->t, &buf, sizeof (buf));
         }
       else
         {
         }
       else
         {
-          c = 13;
-          tty_write (tty, &c, 1);
-          if (v->modes[VT102_MODE_NEWLINE_MODE])
+          ch = 13;
+          c->t->xmit (c->t, &ch, 1);
+          if (c->v->modes[VT102_MODE_NEWLINE_MODE])
             {
             {
-              c = 10;
-              tty_write (tty, &c, 1);
+              ch = 10;
+              c->t->xmit (c->t, &ch, 1);
             }
         }
       break;
             }
         }
       break;
@@ -1319,7 +1331,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
     case KEY_PF4:
       {
         uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
     case KEY_PF4:
       {
         uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
-        tty_write (tty, &buf, sizeof (buf));
+        c->t->xmit (c->t, &buf, sizeof (buf));
       }
       break;
     case KEY_INSERT:
       }
       break;
     case KEY_INSERT:
@@ -1328,7 +1340,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
     case KEY_PGDN:
       {
         uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
     case KEY_PGDN:
       {
         uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
-        tty_write (tty, &buf, sizeof (buf));
+        c->t->xmit (c->t, &buf, sizeof (buf));
       }
       break;
     }
       }
       break;
     }
@@ -1378,12 +1390,12 @@ vt102_reset (VT102 * v)
 }
 
 int
 }
 
 int
-vt102_dispatch (VT102 * v, TTY * tty)
+vt102_dispatch (Context * c)
 {
   char buf[1024];
   int red;
 
 {
   char buf[1024];
   int red;
 
-  red = tty_read (tty, buf, sizeof (buf));
+  red = c->t->recv (c->t, buf, sizeof (buf));
 
   if (red < 0)
     return -1;
 
   if (red < 0)
     return -1;
@@ -1391,26 +1403,26 @@ vt102_dispatch (VT102 * v, TTY * tty)
     return 0;
 
 
     return 0;
 
 
-  vt102_parse (v, buf, red, tty);
+  vt102_parse (c, buf, red);
 
   return 0;
 }
 
 
 int
 
   return 0;
 }
 
 
 int
-vt102_dispatch_one (VT102 * v, TTY * tty)
+vt102_dispatch_one (Context * c)
 {
   char buf;
   int red;
 
 {
   char buf;
   int red;
 
-  red = tty_read (tty, &buf, sizeof (buf));
+  red = c->t->recv (c->t, &buf, sizeof (buf));
 
   if (red < 0)
     return -1;
   if (!red)
     return 0;
 
 
   if (red < 0)
     return -1;
   if (!red)
     return 0;
 
-  vt102_parse_char (v, buf, tty);
+  vt102_parse_char (c, buf);
 
   return 0;
 }
 
   return 0;
 }