From 9d7972be8f555a5ece9a8e7b1b6275a9d7c0b212 Mon Sep 17 00:00:00 2001 From: james <> Date: Thu, 6 Mar 2008 17:21:41 +0000 Subject: *** empty log message *** --- src/raw.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 3 deletions(-) (limited to 'src/raw.c') diff --git a/src/raw.c b/src/raw.c index df54ced..a7f01cd 100644 --- a/src/raw.c +++ b/src/raw.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/03/06 17:21:41 james + * *** empty log message *** + * * Revision 1.2 2008/03/06 16:49:39 james * *** empty log message *** * @@ -28,12 +31,21 @@ typedef struct int wfd; } RX_Raw; +typedef struct +{ + TTY_SIGNATURE; +} RAW_TERMINAL; + + static int rx_raw_rx (RX * _r, int ch) { RX_Raw *r = (RX_Raw *) _r; + int ret; uint8_t c = ch; - return (write (r->wfd, &c, 1) == 1) ? 0 : -1; + printf("RX RAW %d\n",ch); + set_blocking(r->wfd); + ret=(write (r->wfd, &c, 1) == 1) ? 0 : -1; } static void @@ -60,12 +72,95 @@ rx_new_raw (int rfd, int wfd) } +static int +raw_terminal_read (TTY * _t, void *buf, int len) +{ + RAW_TERMINAL *t = (RAW_TERMINAL *) _t; + int red, done = 0; + + set_nonblocking (t->rfd); + + do + { + + red = wrap_read (t->rfd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; + + buf += red; + len -= red; + done += red; + } + while (len); + + + return done; +} + + +static int +raw_terminal_write (TTY * _t, void *buf, int len) +{ + int writ, done = 0; + RAW_TERMINAL *t = (RAW_TERMINAL *) _t; + + set_blocking (t->wfd); + + do + { + + writ = wrap_write (t->wfd, buf, len); + if (writ < 0) + return -1; + + if (!writ) + usleep (1000); + + buf += writ; + len -= writ; + done += writ; + } + while (len); + + + return done; +} + + + +static void raw_terminal_close(TTY *_t) +{ +RAW_TERMINAL *t=(RAW_TERMINAL *)_t; + set_blocking (t->rfd); + set_blocking (t->wfd); + +free(t); +} + TTY * terminal_new_raw (int rfd, int wfd) { -//FIXME - return NULL; + RAW_TERMINAL *t; + + t = (RAW_TERMINAL *) malloc (sizeof (RAW_TERMINAL)); + memset(t,0,sizeof(t)); + + strcpy (t->name, "raw"); + t->rfd = rfd; + t->wfd = wfd; + + set_nonblocking (rfd); + set_nonblocking (wfd); + + t->recv = raw_terminal_read; +// t->xmit = raw_terminal_write; + t->close = raw_terminal_close; + t->blocked = 0; + + return (TTY *) t; } static void @@ -73,7 +168,34 @@ ansi_raw_one_shot (ANSI * a, CRT * c) { } +static int ansi_raw_key(ANSI *a,Context *c,int key) +{ +return c->k->key (c->k, c, key); +} + +static void ansi_raw_parse(ANSI *a,Context *c,uint8_t *buf,int red) +{ +while (red--) +ansi_raw_key(a,c,*(buf++)); +} + +static int +ansi_raw_dispatch (ANSI * a, Context * c) +{ + char buf[1024]; + int red; + + if (!a->terminal) + return 0; + red = a->terminal->recv (a->terminal, buf, sizeof (buf)); + if (red <= 0) + return red; + + ansi_raw_parse (a, c, buf, red); + + return 0; +} static void ansi_raw_free (ANSI * a) { @@ -89,6 +211,7 @@ ansi_new_raw (int rfd, int wfd) memset (ret, 0, sizeof (ANSI)); ret->terminal = terminal_new_raw (rfd, wfd); + ret->dispatch=ansi_raw_dispatch; ret->close = ansi_raw_free; return ret; -- cgit v1.2.3