aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-07 01:05:06 +0000
committerjames <>2008-02-07 01:05:06 +0000
commit6928bcea1545df58c3cda2fecd0d90a27aeee9fe (patch)
tree0f19086c840ab64e39fbc8fd8208b19621d0122c
parent9de8271b7ff6749da455c0224c16962c85d971ec (diff)
downloadsympathy-6928bcea1545df58c3cda2fecd0d90a27aeee9fe.tar.gz
sympathy-6928bcea1545df58c3cda2fecd0d90a27aeee9fe.tar.bz2
sympathy-6928bcea1545df58c3cda2fecd0d90a27aeee9fe.zip
*** empty log message ***
-rw-r--r--src/Makefile.am5
-rw-r--r--src/ansi.c5
-rw-r--r--src/prototypes.h132
-rw-r--r--src/tty.c (renamed from src/testtty.c)132
4 files changed, 205 insertions, 69 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a163fd0..6cfd221 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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}
diff --git a/src/ansi.c b/src/ansi.c
index cf92e71..2154413 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -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);
diff --git a/src/prototypes.h b/src/prototypes.h
index 9418624..c75ddbc 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -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);
diff --git a/src/testtty.c b/src/tty.c
index 11d3ac2..adee8bf 100644
--- a/src/testtty.c
+++ 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 ***
*
@@ -24,6 +27,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);
+}