chiark / gitweb /
*** empty log message ***
authorjames <james>
Thu, 7 Feb 2008 01:02:52 +0000 (01:02 +0000)
committerjames <james>
Thu, 7 Feb 2008 01:02:52 +0000 (01:02 +0000)
src/Makefile.am
src/ansi.c
src/prototypes.h
src/tty.c [moved from src/testtty.c with 51% similarity]

index a163fd058f7304d27c7d91984d844d481722a5a1..6cfd2216f2a4745eef115cb1a8d195772a638f20 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.4  2008/02/07 01:04:16  james
+# *** empty log message ***
+#
 # Revision 1.3  2008/02/07 00:39:13  james
 # *** empty log message ***
 #
@@ -23,7 +26,7 @@
 
 INCLUDES = 
 
-SRCS= ansi.c crt.c html.c libsympathy.c render.c testtty.c version.c vt102.c tty.c
+SRCS= ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c
 CPROTO=cproto
 
 SYMPATHYSRCS=${SRCS}
index cf92e711123c853ddd91ff7d7640be27ae8fa341..215441321e7015db5c69bacf9b5cbf3f62e15446 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.10  2008/02/07 01:02:52  james
+ * *** empty log message ***
+ *
  * Revision 1.9  2008/02/07 00:43:27  james
  * *** empty log message ***
  *
@@ -579,8 +582,10 @@ ansi_dispatch (ANSI * a, VT102 * v)
   if (red <= 0)
     return red;
 
+#if 0
   if (*buf == 3)
     return -1;
+#endif
 
   ansi_parse (a, buf, red, v);
 
index 94186247499e84993fb528728f23978fa3fdae21..c75ddbc31f5bfc6c4574d78b4254702ee5637ddc 100644 (file)
@@ -1,76 +1,74 @@
 /* ansi.c */
-int ansi_read (ANSI * a, void *buf, int n);
-void ansi_write (ANSI * a, char *buf, int n);
-void ansi_getsize (ANSI * a);
-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_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, VT102 * v);
-void ansi_parse_deckey (ANSI * a, VT102 * v);
-void ansi_parse_ansikey (ANSI * a, VT102 * v);
-void ansi_parse_escape (ANSI * a, VT102 * v);
-void ansi_check_escape (ANSI * a, VT102 * v);
-void ansi_parse_char (ANSI * a, int c, VT102 * v);
-void ansi_parse (ANSI * a, char *buf, int len, VT102 * v);
-int ansi_dispatch (ANSI * a, VT102 * v);
+int ansi_read(ANSI *a, void *buf, int n);
+void ansi_write(ANSI *a, char *buf, int n);
+void ansi_getsize(ANSI *a);
+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_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, VT102 *v);
+void ansi_parse_deckey(ANSI *a, VT102 *v);
+void ansi_parse_ansikey(ANSI *a, VT102 *v);
+void ansi_parse_escape(ANSI *a, VT102 *v);
+void ansi_check_escape(ANSI *a, VT102 *v);
+void ansi_parse_char(ANSI *a, int c, VT102 *v);
+void ansi_parse(ANSI *a, char *buf, int len, VT102 *v);
+int ansi_dispatch(ANSI *a, VT102 *v);
 /* 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 */
 struct termios old;
-void testy (void);
+void testy(void);
 /* render.c */
-/* testtty.c */
-int open_fd_to_bash (void);
 /* 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_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);
-int vt102_parse (VT102 * v, char *buf, int len);
-void vt102_parser_reset (VT102_parser * p);
-void vt102_send (VT102 * v, uint8_t key);
-void vt102_reset (VT102 * v);
-int vt102_dispatch (VT102 * v);
-VT102 *vt102_new (TTY * t);
-void vt102_free (VT102 * v);
+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_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);
+int vt102_parse(VT102 *v, char *buf, int len);
+void vt102_parser_reset(VT102_parser *p);
+void vt102_send(VT102 *v, uint8_t key);
+void vt102_reset(VT102 *v);
+int vt102_dispatch(VT102 *v);
+VT102 *vt102_new(TTY *t);
+void vt102_free(VT102 *v);
 /* tty.c */
-TTY *tty_new_test (void);
-int tty_read (TTY * t, void *buf, int len);
-int tty_write (TTY * t, void *buf, int len);
-void tty_free (TTY * t);
+TTY *tty_new_test(void);
+int tty_read(TTY *t, void *buf, int len);
+int tty_write(TTY *t, void *buf, int len);
+void tty_free(TTY *t);
similarity index 51%
rename from src/testtty.c
rename to src/tty.c
index 11d3ac218ee862bf6c3a49c5b1ddb79992b5917a..adee8bfac653de5ad94183dbb02caf998b8cea69 100644 (file)
+++ b/src/tty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.1  2008/02/07 01:02:52  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/06 17:53:28  james
  * *** empty log message ***
  *
@@ -23,6 +26,24 @@ static char rcsid[] = "$Id$";
 
 #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);
+}
+
 static void
 default_termios (struct termios *termios)
 {
@@ -56,7 +77,7 @@ default_termios (struct termios *termios)
 }
 
 
-int
+static int
 open_fd_to_bash (void)          /*thump */
 {
   pid_t child;
@@ -83,3 +104,112 @@ open_fd_to_bash (void)          /*thump */
 
   return fd;
 }
+
+
+TTY *
+tty_new_test (void)
+{
+  TTY *t;
+  t = (TTY *) malloc (sizeof (TTY));
+  t->fd = open_fd_to_bash ();
+
+  set_nonblocking (t->fd);
+
+  return t;
+}
+
+static int
+wrap_read (int fd, void *buf, int len)
+{
+  int red;
+
+  red = read (fd, buf, len);
+  if (!red)
+    return -1;
+
+  if ((red < 0) && (errno == EAGAIN))
+    red = 0;
+
+  return red;
+}
+
+static int
+wrap_write (int fd, void *buf, int len)
+{
+  int writ;
+
+  writ = write (fd, buf, len);
+  if (!writ)
+    return -1;
+
+  if ((writ < 0) && (errno == -EAGAIN))
+    writ = 0;
+
+  return writ;
+}
+
+int
+tty_read (TTY * t, void *buf, int len)
+{
+  int red, done = 0;
+
+
+  do
+    {
+
+      red = wrap_read (t->fd, buf, len);
+      if (red < 0)
+        return -1;
+      if (!red)
+        return done;
+
+      buf += red;
+      len -= red;
+      done += red;
+    }
+  while (len);
+
+
+  return done;
+}
+
+
+int
+tty_write (TTY * t, void *buf, int len)
+{
+  int writ, done = 0;
+
+#if 0
+  {
+    int i;
+    uint8_t *p = buf;
+    for (i = 0; i < len; ++i)
+      fprintf (stderr, "vw: %03o %c\n", p[i], p[i] > 31 ? p[i] : 32);
+  }
+#endif
+
+  do
+    {
+
+      writ = wrap_write (t->fd, buf, len);
+      if (writ < 0)
+        return -1;
+      if (!writ)
+        sleep (1);
+
+      buf += writ;
+      len -= writ;
+      done += writ;
+    }
+  while (len);
+
+
+  return done;
+}
+
+void
+tty_free (TTY * t)
+{
+  close (t->fd);
+  free (t);
+}