chiark / gitweb /
*** empty log message ***
authorjames <james>
Wed, 13 Feb 2008 16:57:29 +0000 (16:57 +0000)
committerjames <james>
Wed, 13 Feb 2008 16:57:29 +0000 (16:57 +0000)
17 files changed:
src/Makefile.am
src/ansi.c
src/ansi.h
src/history.c
src/history.h
src/libsympathy.c
src/project.h
src/prototypes.h
src/ring.c
src/slide.c [new file with mode: 0644]
src/slide.h [new file with mode: 0644]
src/sympathy.h.head.in [moved from src/sympathy.h.in with 89% similarity]
src/sympathy.h.tail [new file with mode: 0644]
src/terminal.c
src/tty.c
src/util.c
src/vt102.c

index 968d9deb8e1e091885968185076a504fe5a7a5f5..efbeda7c44b4f222c1e0bb102157d6ae7a76b7b8 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.9  2008/02/13 16:57:29  james
+# *** empty log message ***
+#
 # Revision 1.8  2008/02/13 09:12:20  james
 # *** empty log message ***
 #
 
 INCLUDES=
 
-HDRS=ansi.h context.h crt.h history.h keys.h project.h prototypes.h \
-       ring.h sympathy.h tty.h vt102.h
+PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h log.h ipc.h context.h prototypes.h
+
+HDRS=project.h 
 
 SRCS=ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c \
-       history.c ring.c ptty.c terminal.c util.c
+       history.c ring.c ptty.c terminal.c util.c log.c ipc.c slide.c
 
 CPROTO=cproto
 
@@ -56,7 +60,7 @@ libsympathy_la_SOURCES = ${SYMPATHYSRCS}
 
 libsympathy_a_CFLAGS = ${AM_CFLAGS}
 
-BUILT_SOURCES = version.h
+BUILT_SOURCES = version.h sympathy.h
 
 lib_LIBRARIES=libsympathy.a
 lib_LTLIBRARIES=libsympathy.la
@@ -85,6 +89,9 @@ protos:
 tidy: ${SRCS} ${HDRS}
        indent -i2 -ts0 ${SRCS} ${HDRS} 
 
+sympathy.h: ${PROJECTHDRS} sympathy.h.head sympathy.h.tail
+       cat sympathy.h.head ${PROJECTHDRS} sympathy.h.tail > $@ || /bin/rm -f $@
+
 version.h: $(VFD)/version-files $(VFD)/version-major \
        $(VFD)/version-minor $(VFD)/version-micro \
        $(VFD)/version-md5sums ${VFS} Makefile
index 12a0563f8f494790113187e0661f3f54b54a3286..7f44957cbb0516b708b7202e16e0b690de73d202 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.19  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.18  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -316,7 +319,7 @@ ansi_cls (ANSI * a)
 
   crt_cls (&a->crt);
 
-  ansi_force_attr_normal (a);
+  ansi_set_attr (a, CRT_ATTR_NORMAL);
   ansi_set_color (a, CRT_COLOR_NORMAL);
   ansi_move (a, p);
   a->terminal->xmit (a->terminal, "\033[2J", 4);
@@ -410,67 +413,173 @@ ansi_spot_scroll (ANSI * a, CRT * c)
 
 
 void
-ansi_draw (ANSI * a, CRT * c)
+ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
 {
-  CRT_Pos p;
-  int o;
-  int hidden_cursor = 0;
+  CRT_Pos p = { 0, y };
+  CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)];
 
-  if (crt_pos_cmp (a->terminal->size, a->size))
+  for (p.x = 0; p.x < CRT_COLS; ++p.x)
     {
-      terminal_getsize (a->terminal);
+      if (p.x >= a->size.x)
+        continue;
 
-      a->size = a->terminal->size;
+      if (crt_ca_cmp (*acap, *cap))
+        {
+          ansi_showhide_cursor (a, 1);
+          *acap = *cap;
 
-      a->pos.x = ANSI_INVAL;
-      a->hide_cursor = ANSI_INVAL;
+          ansi_move (a, p);
+          ansi_render (a, *acap);
+        }
 
-      crt_reset (&a->crt);
+      acap++;
+      cap++;
+    }
+}
+
+void
+ansi_resize_check (ANSI * a)
+{
+
+  if (!crt_pos_cmp (a->terminal->size, a->size))
+    return;
+
+  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);
+  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);
+
+}
+
+#define HISTORY_GUESS_SCROLL 24 /*guess all 24 lines usually scroll */
+/*if they haven't then ansi_draw will patch it up*/
+
+void
+ansi_history (ANSI * a, History * h)
+{
+  char buf[32];
+  int i;
+/*Do we need to catch up on history?*/
+
+  if (a->history_ptr == h->wptr)
+    return;
+  ansi_resize_check (a);
+
+  if ((a->size.x < CRT_COLS) || (a->size.y < CRT_ROWS))
+    return;
+
+  ansi_force_attr_normal (a);
+  ansi_set_color (a, CRT_COLOR_NORMAL);
+
+  i = sprintf (buf, "\033[%d;%dr", 1, HISTORY_GUESS_SCROLL);
+  a->terminal->xmit (a->terminal, buf, i);
+
+
+  while (a->history_ptr != h->wptr)
+    {
+
+      History_ent *e = &h->lines[a->history_ptr];
+
+      HISTORY_INC (h, a->history_ptr);
+
+      if (!e->valid)
+        continue;
+
+      /*If so write the line ot the top of the screen */
+      ansi_draw_line (a, e->line, 0);
+
+
+      /*Roll HISTORY_GUESS_SCROLL lines up putting the top line into the xterm's history */
+
+
+      ansi_showhide_cursor (a, 1);
+      i = sprintf (buf, "\033[%d;%dH", HISTORY_GUESS_SCROLL, 1);
+      a->terminal->xmit (a->terminal, buf, i);
+      a->terminal->xmit (a->terminal, "\033D", 2);
+      a->pos.x = ANSI_INVAL;
+
+      /*now do the same in our image of the screen */
+
+      {
+        CRT_Pos s = { 0 }
+        , e =
+        {
+        0};
+
+        /*scroll lines up */
+        for (s.y++; s.y < HISTORY_GUESS_SCROLL; s.y++, e.y++)
+          {
+            memcpy (&a->crt.screen[CRT_ADDR_POS (&e)],
+                    &a->crt.screen[CRT_ADDR_POS (&s)],
+                    sizeof (CRT_CA) * CRT_COLS);
+          }
+
+        /* erase new line */
+        s.y = e.y;
+        e.x = CRT_COLS - 1;
+        crt_erase (&a->crt, s, e, 1);
+      }
 
     }
+/*reset margins*/
+  a->terminal->xmit (a->terminal, "\033[r", 3);
+  a->pos.x = ANSI_INVAL;
+
+}
+
+
+
+
+void
+ansi_draw (ANSI * a, CRT * c)
+{
+  CRT_Pos p;
+  int o;
+  int hidden_cursor = 0;
+
+  ansi_resize_check (a);
+
 
 
   for (p.y = 0; p.y < CRT_ROWS; ++p.y)
     {
       if (p.y >= a->size.y)
         continue;
-      o = CRT_ADDR (p.y, 0);
-      for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o)
-        {
-          if (p.x >= a->size.x)
-            continue;
-          if (crt_ca_cmp (a->crt.screen[o], c->screen[o]))
-            {
-              ansi_showhide_cursor (a, 1);
-              a->crt.screen[o] = c->screen[o];
 
-              ansi_move (a, p);
-              ansi_render (a, a->crt.screen[o]);
-            }
-        }
+      ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y);
+
     }
 
 
   if ((CRT_COLS > a->size.x) || (CRT_ROWS > a->size.y))
     {
-      char msg[] = "Window is too small";
+      char msg[1024];           // = "Window is too small";
+      int i;
       p.x = 0;
       p.y = 0;
 
+      i =
+        sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x,
+                 a->size.y, CRT_COLS, CRT_ROWS);
+
       ansi_showhide_cursor (a, 1);
       ansi_set_attr (a, CRT_ATTR_REVERSE);
       ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED));
       ansi_move (a, p);
 
-      a->terminal->xmit (a->terminal, msg, sizeof (msg));
+      a->terminal->xmit (a->terminal, msg, i);
       a->pos.x = ANSI_INVAL;
     }
 
@@ -489,10 +598,19 @@ ansi_draw (ANSI * a, CRT * c)
 }
 
 void
-ansi_reset (ANSI * a)
+ansi_reset (ANSI * a, CRT * c)
 {
   a->size.x = -1;
-  ansi_draw (a, &a->crt);
+  ansi_draw (a, c ? c : &a->crt);
+}
+
+void
+ansi_terminal_reset (ANSI * a)
+{
+  CRT_Pos p = { 0, CRT_ROWS };
+  ansi_force_attr_normal (a);
+
+  ansi_move (a, p);
 }
 
 void
@@ -682,6 +800,10 @@ ansi_dispatch (ANSI * a, Context * c)
 
   ansi_check_escape (a, c);
 
+
+  if (!a->terminal)
+    return;
+
   red = a->terminal->recv (a->terminal, buf, sizeof (buf));
   if (red <= 0)
     return red;
@@ -691,9 +813,18 @@ ansi_dispatch (ANSI * a, Context * c)
     return -1;
 #endif
 
-#if 0
+#if 1
   if (*buf == 1)
-    return 1;
+    {
+      ansi_reset (a, NULL);
+      return 0;
+    }
+  if (*buf == 2)
+    {
+      a->history_ptr = c->h->wptr;
+      HISTORY_INC (c->h, a->history_ptr);
+      return 0;
+    }
 #endif
 
 
@@ -701,3 +832,11 @@ ansi_dispatch (ANSI * a, Context * c)
 
   return 0;
 }
+
+
+void
+ansi_update (ANSI * a, Context * c)
+{
+  ansi_history (a, c->h);
+  ansi_draw (a, &c->v->crt);
+}
index 1368adaa442a7a54779be6640644d1c73aafef6f..7aa5935e690c7b0282fb1c4013017fb4cea9ddcf 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.7  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/13 01:08:18  james
  * *** empty log message ***
  *
@@ -50,6 +53,8 @@ typedef struct
 
 typedef struct
 {
+  ANSI_Parser parser;
+
   TTY *terminal;
 
   CRT crt;
@@ -59,7 +64,8 @@ typedef struct
   int attr;
   int color;
 
-  ANSI_Parser parser;
+
+  int history_ptr;
 } ANSI;
 
 
index b8637aae63380be2143753a1b52eb5295a512ef3..24d3692de1815a309ec40cbbd51a61bbd7badd82 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
@@ -49,13 +52,28 @@ history_free (History * h)
 void
 history_add (History * h, CRT_CA * c)
 {
+  History_ent *e;
   if (!h)
     return;
 
-  memcpy (h->lines[h->wptr].line, c, sizeof (CRT_CA) * CRT_COLS);
-  h->wptr++;
+  e = &h->lines[h->wptr];
+  HISTORY_INC (h, h->wptr);
+
+  memcpy (e->line, c, sizeof (CRT_CA) * CRT_COLS);
+  time (&e->t);
+  e->valid = 1;
+
+#if 0
+  {
+    int i = CRT_COLS;
+    while (i--)
+      {
+        fputc (c->chr, stderr);
+        c++;
+      }
+    fputc ('\n', stderr);
+  }
+#endif
 
-  if (h->wptr == h->nlines)
-    h->wptr = 0;
 
 }
index 79661afd674496ec131e949193ac4d0c56f7fb9a..5c5dd52cd0bb8530581fceff5d0654236ca2dbef 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/12 22:36:46  james
  * *** empty log message ***
  *
@@ -37,4 +40,6 @@ typedef struct
   int wptr;
 } History;
 
+#define HISTORY_INC(h,a) do { (a)++; if ((a)==((h)->nlines)) { (a)=0; }; } while (0)
+
 #endif /* __HISTORY_H__ */
index 989b664a7f433596a3823cae2214275cc827c4f2..d05ad13bbfa855473fe795c40deff1b9f3ccdc74 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.17  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.16  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -64,71 +67,3 @@ static char rcsid[] =
 
 #include "project.h"
 
-
-
-void
-testy (void)
-{
-  fd_set rfd;
-  struct termios raw = { 0 };
-  ANSI a = { 0 };
-  Context c;
-
-#if 0
-  int fd;
-  char c;
-
-  TTY *t;
-  VT102 *v;
-  History *h;
-  int i;
-#endif
-
-
-
-  ansi_reset (&a);
-
-
-  c.t = ptty_open (NULL, NULL);
-  c.v = vt102_new ();
-  c.h = history_new (200);
-  c.l = NULL;
-
-  terminal_register_handlers ();
-  a.terminal = terminal_open (0, 1);
-
-
-  FD_ZERO (&rfd);
-  for (;;)
-    {
-      struct timeval tv = { 0, 100000 };
-
-
-      FD_SET (c.t->rfd, &rfd);
-      FD_SET (a.terminal->rfd, &rfd);
-
-      select (FD_SETSIZE, &rfd, NULL, NULL, &tv);
-
-      ansi_dispatch (&a, &c);
-
-      if (FD_ISSET (c.t->rfd, &rfd))
-        {
-          if (vt102_dispatch (&c))
-            break;
-        }
-
-#if 0
-      if (had_winch)
-        {
-          had_winch = 0;
-          ansi_getsize (&a);
-          ansi_reset (&a);
-          ansi_draw (&a, &v->crt);
-        }
-#endif
-      //FIXME history
-      ansi_draw (&a, &c.v->crt);
-    }
-
-  terminal_atexit ();
-}
index ed331238bb2b7af1ef3919ea7afbf36d1ba3fe8c..c30ff77da59f385efbcc5a2d9ce827a004710c56 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.8  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.7  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -78,6 +81,8 @@
 #include <sys/int_types.h>
 #endif
 
+#include <string.h>
+#include <strings.h>
 #include <termio.h>
 #include <termios.h>
 #include <signal.h>
 #include <utmp.h>
 #include <pty.h>
 
-#include "crt.h"
-#include "tty.h"
-#include "ansi.h"
-#include "vt102.h"
-#include "keys.h"
-#include "history.h"
-#include "ring.h"
-#include "log.h"
-
-#include "context.h"
-
-#include "prototypes.h"
+#include "sympathy.h"
 
 #endif /* __PROJECT_H__ */
index 635f594355e12ba2bb680eee04e2078d2e044962..df2d7d5346e13f0c68ade3d78a0642eff18e0d39 100644 (file)
 /* 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);
-void ansi_draw_line (ANSI * a, CRT_CA * cap, int y);
-void ansi_resize_check (ANSI * a);
-void ansi_history (ANSI * a, History * h);
-void ansi_draw (ANSI * a, CRT * c);
-void ansi_reset (ANSI * a, CRT * c);
-void ansi_terminal_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);
+int terminal_winches;
+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_line(ANSI *a, CRT_CA *cap, int y);
+void ansi_resize_check(ANSI *a);
+void ansi_history(ANSI *a, History *h);
+void ansi_draw(ANSI *a, CRT *c);
+void ansi_reset(ANSI *a, CRT *c);
+void ansi_terminal_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_update(ANSI *a, Context *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 */
-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 */
-void testy (void);
-void ring_test (void);
 /* render.c */
 /* version.c */
 /* vt102.c */
-void vt102_log_line (Context * c, int line);
-void vt102_history (Context * c, CRT_Pos t, CRT_Pos b);
-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);
+void vt102_log_line(Context *c, int line);
+void vt102_history(Context *c, CRT_Pos t, CRT_Pos b);
+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 */
+void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds);
 /* 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 */
-int ring_read (Ring * r, void *b, int n);
-int ring_write (Ring * r, void *b, int n);
-int ring_space (Ring * r);
-int ring_bytes (Ring * r);
-Ring *ring_new (int n);
+int ring_read(Ring *r, void *b, int n);
+int ring_write(Ring *r, void *b, int n);
+int ring_space(Ring *r);
+int ring_bytes(Ring *r);
+Ring *ring_new(int n);
 /* 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);
+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);
+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);
 /* log.c */
-Log *file_log_new (char *fn);
+Log *file_log_new(char *fn);
 /* ipc.c */
-Socket *socket_listen (char *path);
-Socket *socket_accept (Socket * l);
-Socket *socket_connect (char *path);
-void socket_postselect (Socket * s, fd_set * rfds, fd_set * wfds);
-void socket_preselect (Socket * s, fd_set * rfds, fd_set * wfds);
+Socket *socket_listen(char *path);
+Socket *socket_accept(Socket *l);
+Socket *socket_connect(char *path);
+Socket *socket_postselect(Socket *s, fd_set *rfds, fd_set *wfds);
+void socket_preselect(Socket *s, fd_set *rfds, fd_set *wfds);
 /* slide.c */
-void slide_free (Slide * s);
-void slide_consume (Slide * s, int n);
-void slide_added (Slide * s, int n);
-Slide *slide_new (int n);
-void slide_expand (Slide * s, int n);
+void slide_free(Slide *s);
+void slide_consume(Slide *s, int n);
+void slide_added(Slide *s, int n);
+Slide *slide_new(int n);
+void slide_expand(Slide *s, int n);
index ccd97edc426f2d281e64ce4f46b09688c30a2148..ca412abc25ead6339627756d04be1e014cd14cf9 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.4  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -59,6 +62,27 @@ ring_write (Ring * r, void *b, int n)
   return writ;
 }
 
+int
+ring_space (Ring * r)
+{
+  int i;
+
+  i = r->size - RING_NEXT_W (r) + r->rptr;
+  i %= r->size;
+  return i;
+}
+
+int
+ring_bytes (Ring * r)
+{
+  int i;
+
+  i = r->size + r->wptr - r->rptr;
+  i %= r->size;
+  return i;
+}
+
+
 
 
 Ring *
diff --git a/src/slide.c b/src/slide.c
new file mode 100644 (file)
index 0000000..e20d0be
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * slide.c:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+static char rcsid[] = "$Id$";
+
+/*
+ * $Log$
+ * Revision 1.1  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
+ * 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.1  2008/02/08 15:06:42  james
+ * *** empty log message ***
+ *
+ */
+
+#include "project.h"
+
+void
+slide_free (Slide * s)
+{
+  free (s->slide);
+  free (s);
+}
+
+void
+slide_consume (Slide * s, int n)
+{
+  s->nbytes -= n;
+  memmove (s->slide, s->slide + n, s->nbytes);
+
+  if ((s->size > s->target_size) && (s->nbytes <= s->size))
+    {
+      s->size = s->target_size;
+      s->slide = realloc (s->slide, s->size);
+    }
+
+}
+
+void
+slide_added (Slide * s, int n)
+{
+  s->nbytes += n;
+}
+
+Slide *
+slide_new (int n)
+{
+  Slide *ret = (Slide *) malloc (sizeof (Slide));
+
+  ret->slide = (uint8_t *) malloc (n);
+  ret->size = n;
+  ret->target_size = n;
+  ret->nbytes = 0;
+
+  return ret;
+}
+
+
+void
+slide_expand (Slide * s, int n)
+{
+  n += s->nbytes;
+
+  if (n <= s->size)
+    return;
+
+  while (n > s->size)
+    s->size <<= 1;
+
+//FIXME -- might fail
+  s->slide = realloc (s->slide, s->size);
+
+}
diff --git a/src/slide.h b/src/slide.h
new file mode 100644 (file)
index 0000000..d9a7059
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * ring.h:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * $Log$
+ * Revision 1.1  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
+ * Revision 1.1  2008/02/08 15:06:42  james
+ * *** empty log message ***
+ *
+ */
+
+#ifndef __SLIDE_H__
+#define __SLIDE_H__
+
+typedef struct
+{
+  uint8_t *slide;
+  int nbytes;
+  int target_size;
+  int size;
+} Slide;
+
+#define SLIDE_FULL(s) ((s)->nbytes==(s)->size)
+#define SLIDE_EMPTY(s) (!((s)->nbytes))
+#define SLIDE_SPACE(s) (((s)->size)-((s)->nbytes))
+#define SLIDE_BYTES(s) ((s)->nbytes)
+#define SLIDE_RPTR(s) ((s)->slide)
+#define SLIDE_WPTR(s) (((s)->slide)+((s)->nbytes))
+
+#endif /* __SLIDE_H__ */
similarity index 89%
rename from src/sympathy.h.in
rename to src/sympathy.h.head.in
index ea79d89a9d8b6eb748ea23a82a7bfb70587d2587..a703ce258f01b7eb47db36180040c94e6901a569 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * sympathy.h.in:
+ * sympathy.h.head.in:
  *
  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
  * All rights reserved.
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.1  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/03 16:20:24  james
  * *** empty log message ***
  *
@@ -49,8 +52,4 @@ extern "C" {
 /*get struct tm defined*/
 #include <@G2_TM_H@>
 
-#ifdef __cplusplus
-}
-#endif
 
-#endif /* __SYMPATHY_H__ */
diff --git a/src/sympathy.h.tail b/src/sympathy.h.tail
new file mode 100644 (file)
index 0000000..19a7bad
--- /dev/null
@@ -0,0 +1,5 @@
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SYMPATHY_H__ */
index 1223c0f0b677d610edca450c99e9ec83baac20af..7bbc761080aa390b9c0944efaac8f0f9d446619f 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.4  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -58,6 +61,9 @@ int terminal_winches;
 static void
 terminal_close (TTY * _t)
 {
+  char buf[32];
+  int i;
+
   TERMINAL *t = (TERMINAL *) _t;
   TERMINAL **ptr = &terminal_list;
 
@@ -73,6 +79,14 @@ terminal_close (TTY * _t)
 
   tcsetattr (t->wfd, TCSANOW, &t->orig_termios);
 
+  set_nonblocking (t->wfd);
+
+
+  t->xmit (t, "\033[r", 3);
+  t->xmit (t, "\033[0m", 4);
+  i = sprintf (buf, "\033[%d;%dH", CRT_ROWS + 1, 1);
+  t->xmit (t, buf, i);
+
   set_blocking (t->rfd);
   set_blocking (t->wfd);
 
@@ -147,6 +161,7 @@ terminal_read (TTY * _t, void *buf, int len)
   int red, done = 0;
 
   terminal_dispatch ();
+  set_nonblocking (t->rfd);
 
   do
     {
@@ -176,14 +191,17 @@ terminal_write (TTY * _t, void *buf, int len)
 
   terminal_dispatch ();
 
+  set_blocking (t->wfd);
+
   do
     {
 
       writ = wrap_write (t->wfd, buf, len);
       if (writ < 0)
         return -1;
+
       if (!writ)
-        sleep (1);
+        usleep (1000);
 
       buf += writ;
       len -= writ;
@@ -234,7 +252,8 @@ terminal_open (int rfd, int wfd)
   set_nonblocking (wfd);
 
 
-  raw_termios (&termios);
+  cfmakeraw (&termios);
+  //raw_termios (&termios);
 
   tcsetattr (wfd, TCSANOW, &termios);
 
index 72b31a12f161cfe615255166559466a585aaeba2..ca4936bbc81b3c03a24aef54481bb2933307e4e9 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.6  2008/02/13 16:59:34  james
+ * *** empty log message ***
+ *
  * Revision 1.5  2008/02/13 16:57:29  james
  * *** empty log message ***
  *
@@ -22,12 +25,12 @@ static char rcsid[] = "$Id$";
  */
 
 
-
+#include "project.h"
 
 void
 tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds)
 {
-  FD_SET (t->rfd, &rfds);
+  FD_SET (t->rfd, rfds);
 }
 
 #if 0
index bd838b90a6de5f234a0fe44465dc43ccf358207d..0a74869144b5cc2ae69dd15d22985dd0c1c990eb 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.3  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.2  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -40,11 +43,14 @@ wrap_write (int fd, void *buf, int len)
 {
   int writ;
 
+  errno = 0;
+
   writ = write (fd, buf, len);
+
   if (!writ)
     return -1;
 
-  if ((writ < 0) && (errno == -EAGAIN))
+  if ((writ < 0) && (errno == EAGAIN))
     writ = 0;
 
   return writ;
index a8d4388610ccccaa82b16c0c6631784fa8723718..df7b6b12e02c22098f6ffa1dbbea938ff1534772 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.25  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.24  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -264,6 +267,18 @@ vt102_log_line (Context * c, int line)
   c->l->log (c->l, logbuf);
 }
 
+/*Called for every upward scroll with same args*/
+void
+vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
+{
+/*Only log if it scrolls off the top*/
+  if (t.y)
+    return;
+
+  t.x = 0;
+  history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
+}
+
 void
 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
 {
@@ -314,7 +329,9 @@ vt102_cursor_advance_line (Context * c)
       (couldscroll))
     {
       vt102_log_line (c, v->pos.y);
-      //FIXME call out to history
+
+      vt102_history (c, v->top_margin, v->bottom_margin);
+
       crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
       return;
     }
@@ -776,6 +793,7 @@ vt102_parse_esc (Context * c, int ch)
       if (v->pos.y == v->bottom_margin.y)
         {
           vt102_log_line (c, v->pos.y);
+          vt102_history (c, v->top_margin, v->bottom_margin);
           crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
         }
       else
@@ -938,8 +956,8 @@ vt102_parse_csi (Context * c, char *buf, int len)
             {
               while (narg--)
                 {
-                  //FIXME call out to history
-                  crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
+                  vt102_history (c, v->pos, v->bottom_margin);
+                  crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1);
                 }
             }
           break;