diff options
-rw-r--r-- | apps/mainloop.c | 75 | ||||
-rw-r--r-- | apps/mainloop.h | 8 | ||||
-rw-r--r-- | apps/sympathy.c | 60 | ||||
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/ansi.c | 388 | ||||
-rw-r--r-- | src/ansi.h | 11 | ||||
-rw-r--r-- | src/context.h | 4 | ||||
-rw-r--r-- | src/html.c | 6 | ||||
-rw-r--r-- | src/prototypes.h | 322 | ||||
-rw-r--r-- | src/raw.c | 87 | ||||
-rw-r--r-- | src/rx.h | 9 | ||||
-rw-r--r-- | src/tty.c | 15 | ||||
-rw-r--r-- | src/utf8.c | 39 | ||||
-rw-r--r-- | src/vt102.c | 23 |
14 files changed, 607 insertions, 449 deletions
diff --git a/apps/mainloop.c b/apps/mainloop.c index dd553e3..5772214 100644 --- a/apps/mainloop.c +++ b/apps/mainloop.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.23 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.22 2008/03/03 06:04:42 james * *** empty log message *** * @@ -121,7 +124,6 @@ static char rcsid[] = #include "clients.h" -Context *context; typedef struct { @@ -378,6 +380,7 @@ check_status (Context * c, Clients * cs) static int msg_from_server (ANSI * a, IPC_Msg * m, Context * c) { +int err=0; switch (m->hdr.type) { @@ -398,11 +401,11 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c) if (a->one_shot) { a->one_shot (a, &c->v->crt); - return 1; + err++;/*Simulate a fatal write error enclosing tty*/ } break; case IPC_MSG_TYPE_TERM: - tty_parse (c, m->term.term, m->term.len); + err+=tty_parse (c, m->term.term, m->term.len); break; case IPC_MSG_TYPE_STATUS: cmd_new_status (c->d, c, m->status.status); @@ -410,54 +413,46 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c) default: fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); } - return 0; + return err; } void -mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, - ANSI * ansi, Log * log, int nhistory, CRT_Pos * size) +mainloop ( Context *c, ANSI *ansi,Socket * server_socket, Socket * client_socket) { fd_set rfds, wfds; - Context c = { 0 }; Clients *clients; - context = &c; + c->tp = tty_parser_new (); + c->u = utf8_new (); - c.tp = tty_parser_new (); - c.u = utf8_new (); - - c.v = vt102_new (size); - c.h = history_new (nhistory); - c.l = log; /* are we being fed by a tty or a socket */ if (client_socket) { if (server_socket) abort (); - c.k = keydis_ipc_new (client_socket); + c->k = keydis_ipc_new (client_socket); } else { - if (!tty) + if (!c->t) abort (); - c.t = tty; - c.k = keydis_vt102_new (); + c->k = keydis_vt102_new (); } /* do we have an upstream terminal to talk to */ /* if so start a command parser */ if (ansi) { - c.d = cmd_new (); + c->d = cmd_new (); } else { - c.d = NULL; + c->d = NULL; } - vt102_reset (&c); + vt102_reset (c); if (server_socket) @@ -475,18 +470,18 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, { struct timeval tv = { 0, 250000 }; - if ((c.d) && (c.d->disconnect)) + if ((c->d) && (c->d->disconnect)) break; /*update the status lines, locally or remotely */ - if (c.t) - check_status (&c, clients); + if (c->t) + check_status (c, clients); FD_ZERO (&rfds); FD_ZERO (&wfds); - if (c.t) - tty_pre_select (c.t, &rfds, &wfds); + if (c->t) + tty_pre_select (c->t, &rfds, &wfds); if (server_socket) { @@ -513,24 +508,24 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Client *new_client; /*New client connexion */ new_client = - clients_new_client (clients, new_client_socket, &c); + clients_new_client (clients, new_client_socket, c); - send_history (c.h, new_client); - send_vt102 (c.v, new_client); + send_history (c->h, new_client); + send_vt102 (c->v, new_client); } } - clients_post_select (clients, &c, &rfds, &wfds); + clients_post_select (clients, c, &rfds, &wfds); } /*any data from the port */ - if (c.t && FD_ISSET (c.t->rfd, &rfds)) + if (c->t && FD_ISSET (c->t->rfd, &rfds)) { char buf[IPC_MAX_BUF]; int red; - red = c.t->recv (c.t, buf, sizeof (buf)); + red = c->t->recv (c->t, buf, sizeof (buf)); if (red < 0) break; @@ -539,7 +534,8 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, { if (clients) send_output (clients, buf, red); - tty_parse (&c, buf, red); + if (tty_parse (c, buf, red)) + break; } } @@ -548,19 +544,16 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, /*any data from the server */ if (client_socket) { - int one_shot; if (socket_post_select (client_socket, &rfds, &wfds)) break; while (client_socket->msg) { - if (msg_from_server (ansi, client_socket->msg, &c)) - one_shot++; + if (msg_from_server (ansi, client_socket->msg, c)) + break; socket_consume_msg (client_socket); } - if (one_shot) - break; } @@ -568,10 +561,12 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, if (ansi) { if (ansi->dispatch) - ansi->dispatch (ansi, &c); + if (ansi->dispatch (ansi, c)) + break; if (ansi->update) - ansi->update (ansi, &c); + if (ansi->update (ansi, c)) + break; } } diff --git a/apps/mainloop.h b/apps/mainloop.h index 418b641..e85b784 100644 --- a/apps/mainloop.h +++ b/apps/mainloop.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.8 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.7 2008/03/03 06:04:42 james * *** empty log message *** * @@ -40,8 +43,5 @@ #include <sympathy.h> -extern void -mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, ANSI * a, - Log * log, int nhistory, CRT_Pos * size); - +extern void mainloop (Context *,ANSI *a,Socket *,Socket *); #endif /* __MAINLOOP_H__ */ diff --git a/apps/sympathy.c b/apps/sympathy.c index f5ed2e0..dc9dd66 100644 --- a/apps/sympathy.c +++ b/apps/sympathy.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.33 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.32 2008/03/03 06:04:42 james * *** empty log message *** * @@ -433,11 +436,14 @@ get_hostname (void) int main (int argc, char *argv[]) { + Context ctx_store={0},*ctx=&ctx_store; int c; extern char *optarg; extern int optind, opterr, optopt; CRT_Pos size = { VT102_COLS_80, VT102_ROWS_24 }; + ANSI *ansi=NULL; + int csnok_pipe[2] = { 0 }; int csnok = 0; @@ -445,9 +451,6 @@ main (int argc, char *argv[]) char *oargs[128]; Socket *server_socket = NULL, *client_socket = NULL; - ANSI *ansi = NULL; - TTY *tty = NULL; - Log *log = NULL; int history = 200; int pid; @@ -458,7 +461,7 @@ main (int argc, char *argv[]) memset (oflags, 0, sizeof (oflags)); memset (oargs, 0, sizeof (oargs)); - while ((c = getopt (argc, argv, "RP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF) + while ((c = getopt (argc, argv, "I:NRP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF) { switch (c) { @@ -548,6 +551,9 @@ main (int argc, char *argv[]) if (oflags['c'] && oflags['s'] && oflags['F']) fatal_moan ("-F is incompatible with -c -s"); + if (oflags['H'] && oflags['N']) + fatal_moan ("-H is incompatible with -N"); + /*implement server and client: this process forks. The parent */ /*becomes the client and the child forks again to become the */ /*server. If there's no -k argument the client (parent) needs */ @@ -566,6 +572,8 @@ main (int argc, char *argv[]) case 0: /*child becomes the server */ oflags['c'] = 0; oflags['H'] = 0; + oflags['N'] = 0; + oflags['I'] = 0; if (csnok) close (csnok_pipe[0]); @@ -612,6 +620,9 @@ main (int argc, char *argv[]) if (oflags['c'] && !oflags['k'] && !oflags['r']) fatal_moan ("-c requires a socket to be specified with -s or -k or -r"); + if ((oflags['H'] || oflags['N'] || oflags['I'] ) && oflags['s']) + fatal_moan("-s is incompatible with -H, -N and -I"); + if ((oflags['p'] || oflags['d'] || oflags['K'] || oflags['b'] || oflags['f'] || oflags['L'] || oflags['R'] || oflags['P']) && oflags['c']) fatal_moan @@ -701,15 +712,15 @@ main (int argc, char *argv[]) if (oflags['L']) { - log = file_log_new (oargs['L'], oflags['R']); - if (!log) + ctx->l = file_log_new (oargs['L'], oflags['R']); + if (!ctx->l) fatal_moan ("unable to access log file %s", oargs['L']); } if (oflags['p']) { - tty = ptty_open (NULL, NULL, &size); - if (!tty) + ctx->t = ptty_open (NULL, NULL, &size); + if (!ctx->t) fatal_moan ("unable to open a ptty"); } else @@ -740,11 +751,11 @@ main (int argc, char *argv[]) fatal_moan ("/proc/cmdline contains %s", search_string); } - tty = + ctx->t = serial_open (oargs['d'], oflags['K'] ? SERIAL_LOCK_ACTIVE : SERIAL_LOCK_PASSIVE); - if (!tty) + if (!ctx->t) fatal_moan ("unable to open serial port %s", oargs['d']); } @@ -755,11 +766,11 @@ main (int argc, char *argv[]) if (baud < 0) fatal_moan ("Unable to parse baudrate %s", oargs['b']); - tty_set_baud (tty, baud); + tty_set_baud (ctx->t, baud); } - tty_set_flow (tty, oflags['f'] ? 1 : 0); + tty_set_flow (ctx->t, oflags['f'] ? 1 : 0); } @@ -795,8 +806,10 @@ main (int argc, char *argv[]) if (oflags['c'] || oflags['t']) { - - if (oflags['H']) + if (oflags['N']) { + ctx->r=rx_new_raw(0,1); + ansi=ansi_new_raw(0,1); + } else if (oflags['H']) { ansi = ansi_new_html (stdout); } @@ -808,9 +821,18 @@ main (int argc, char *argv[]) oflags['u'] ? 0 : 1); ansi->reset (ansi, NULL); } + if (oflags['I']) { + //FIXME ... + } } - mainloop (tty, server_socket, client_socket, ansi, log, history, &size); + + ctx->v = vt102_new (&size); + ctx->h = history_new (history); + + mainloop (ctx,ansi, server_socket, client_socket); + +// mainloop (tty, server_socket, client_socket, ansi, log, history, &size); if (ansi) { @@ -818,11 +840,11 @@ main (int argc, char *argv[]) terminal_atexit (); } - if (tty) - tty->close (tty); + if (ctx->t) + ctx->t->close (ctx->t); - if (log) - log->close (log); + if (ctx->l) + ctx->l->close (ctx->l); if (server_socket) socket_free (server_socket); if (client_socket) diff --git a/src/Makefile.am b/src/Makefile.am index 7c1d902..6cdefe7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@ # $Id$ # # $Log$ +# Revision 1.23 2008/03/06 16:49:05 james +# *** empty log message *** +# # Revision 1.22 2008/03/03 06:04:18 james # *** empty log message *** # @@ -82,8 +85,8 @@ INCLUDES= # NB order here matters. PROJECTHDRS= crt.h utf8.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h \ - log.h ipc.h symsocket.h keydis.h cmd.h lockfile.h context.h \ - vt102_charset.h prototypes.h + log.h ipc.h symsocket.h keydis.h cmd.h lockfile.h rx.h \ + context.h vt102_charset.h prototypes.h HDRS=project.h ${PROJECTHDRS} @@ -91,7 +94,7 @@ HDRS=project.h ${PROJECTHDRS} SRCS=ansi.c crt.c html.c libsympathy.c render.c version.c vt102.c tty.c \ keydis.c history.c ring.c ptty.c terminal.c util.c log.c ipc.c \ slide.c symsocket.c serial.c cmd.c lockfile.c utf8.c vt102_charset.c \ - rotate.c + rotate.c raw.c CPROTO=cproto @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.44 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.43 2008/03/06 01:41:48 james * *** empty log message *** * @@ -143,13 +146,14 @@ static char rcsid[] = "$Id$"; #include "project.h" -static void +static int ansi_move (ANSI * a, CRT_Pos p) { char buf[16]; int n; int dx = p.x - a->pos.x; int dy = p.y - a->pos.y; + int err = 0; // a->pos.x = ANSI_INVAL; @@ -157,110 +161,131 @@ ansi_move (ANSI * a, CRT_Pos p) { if ((!dx) && (!dy)) - return; + return 0; if (!dy) { if (dx == 1) { - a->terminal->xmit (a->terminal, "\033[C", 3); + if (a->terminal->xmit (a->terminal, "\033[C", 3) != 3) + err++; } else if (dx == -1) { - a->terminal->xmit (a->terminal, "\033[D", 3); + if (a->terminal->xmit (a->terminal, "\033[D", 3) != 3) + err++; } else { n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } } else if (!dx) { if (dy == -1) { - a->terminal->xmit (a->terminal, "\033[A", 3); + if (a->terminal->xmit (a->terminal, "\033[A", 3) != 3) + err++; } else if (dy == 1) { - a->terminal->xmit (a->terminal, "\033[B", 3); + if (a->terminal->xmit (a->terminal, "\033[B", 3) != 3) + err++; } else if (dy < 0) { n = snprintf (buf, sizeof (buf), "\033[%dA", -dy); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } else { n = snprintf (buf, sizeof (buf), "\033[%dB", dy); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } } else if (!p.x) { if (dy == 1) { - a->terminal->xmit (a->terminal, "\033[E", 3); + if (a->terminal->xmit (a->terminal, "\033[E", 3) != 3) + err++; } else if (dy == -1) { - a->terminal->xmit (a->terminal, "\033[F", 3); + if (a->terminal->xmit (a->terminal, "\033[F", 3) != 3) + err++; } else if (dy > 0) { n = snprintf (buf, sizeof (buf), "\033[%dE", dy); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } else { n = snprintf (buf, sizeof (buf), "\033[%dF", -dy); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } } else { n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } } else { n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); - a->terminal->xmit (a->terminal, buf, n); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; } a->pos = p; + + return err; } -static void +static int ansi_showhide_cursor (ANSI * a, int hide) { + int err = 0; if (a->hide_cursor == hide) - return; + return err; if (hide) { - a->terminal->xmit (a->terminal, "\033[?25l", 6); + if (a->terminal->xmit (a->terminal, "\033[?25l", 6) != 6) + err++; } else { - a->terminal->xmit (a->terminal, "\033[?25h", 6); + if (a->terminal->xmit (a->terminal, "\033[?25h", 6) != 6) + err++; } a->hide_cursor = hide; + return err; } -static void +static int ansi_force_attr_normal (ANSI * a) { - a->terminal->xmit (a->terminal, "\033[0m", 4); + if (a->terminal->xmit (a->terminal, "\033[0m", 4) != 4) + return 1; a->attr = CRT_ATTR_NORMAL; a->color = ANSI_INVAL; + return 0; } -static void +static int ansi_set_color (ANSI * a, int color) { int dif; @@ -268,48 +293,51 @@ ansi_set_color (ANSI * a, int color) int i; int fg, bg; - if ((a->color == ANSI_INVAL) || (color != a->color)) - { - fg = CRT_COLOR_FG (color); - bg = CRT_COLOR_BG (color); + if ((a->color != ANSI_INVAL) && (color == a->color)) + return 0; + fg = CRT_COLOR_FG (color); + bg = CRT_COLOR_BG (color); - if (fg & CRT_COLOR_INTENSITY) - { - fg += 90; - } - else - { - fg += 30; - } + if (fg & CRT_COLOR_INTENSITY) + { + fg += 90; + } + else + { + fg += 30; + } - if (bg & CRT_COLOR_INTENSITY) - { - bg += 100; - } - else - { - bg += 40; - } + if (bg & CRT_COLOR_INTENSITY) + { + bg += 100; + } + else + { + bg += 40; + } - i = sprintf (buf, "\033[%d;%dm", fg, bg); + i = sprintf (buf, "\033[%d;%dm", fg, bg); #if 0 - fprintf (stderr, "Color set to %d %d %x\n", fg, bg, color); + fprintf (stderr, "Color set to %d %d %x\n", fg, bg, color); #endif - a->terminal->xmit (a->terminal, buf, i); - a->color = color; - } + if (a->terminal->xmit (a->terminal, buf, i) != i) + return 1; + a->color = color; + + return 0; } -static void +static int ansi_set_attr (ANSI * a, int attr) { int dif; + int err = 0; dif = attr ^ a->attr; if (!dif) - return; + return 0; a->attr = attr; @@ -325,40 +353,48 @@ ansi_set_attr (ANSI * a, int attr) { if (attr & CRT_ATTR_UNDERLINE) { - a->terminal->xmit (a->terminal, "\033[4m", 4); + if (a->terminal->xmit (a->terminal, "\033[4m", 4)) + err++; } else { - a->terminal->xmit (a->terminal, "\033[24m", 5); + if (a->terminal->xmit (a->terminal, "\033[24m", 5)) + err++; } } if (dif & CRT_ATTR_REVERSE) { if (attr & CRT_ATTR_REVERSE) { - a->terminal->xmit (a->terminal, "\033[7m", 4); + if (a->terminal->xmit (a->terminal, "\033[7m", 4)) + err++; } else { - a->terminal->xmit (a->terminal, "\033[27m", 5); + if (a->terminal->xmit (a->terminal, "\033[27m", 5)) + err++; } } if (dif & CRT_ATTR_BOLD) { if (attr & CRT_ATTR_BOLD) { - a->terminal->xmit (a->terminal, "\033[1m", 4); + if (a->terminal->xmit (a->terminal, "\033[1m", 4)) + err++; } else { - a->terminal->xmit (a->terminal, "\033[21m", 5); - a->terminal->xmit (a->terminal, "\033[22m", 5); + if (a->terminal->xmit (a->terminal, "\033[21m", 5)) + err++; + if (a->terminal->xmit (a->terminal, "\033[22m", 5)) + err++; } } + return err; } -static void +static int ascii_emit (TTY * t, uint32_t ch) { int i; @@ -382,8 +418,7 @@ ascii_emit (TTY * t, uint32_t ch) if (ch < 0x7f) { uint8_t c = ch; - t->xmit (t, &c, 1); - return; + return (t->xmit (t, &c, 1) == 1) ? 0 : -1; } for (i = 0; i < VT102_CHARSET_SIZE; ++i) @@ -391,18 +426,18 @@ ascii_emit (TTY * t, uint32_t ch) if (vt102_charset_gl[i] == ch) { uint8_t c[3] = { 016, i, 017 }; - t->xmit (t, &c, 3); - return; + return (t->xmit (t, &c, 3) == 3) ? 0 : -1; } } - t->xmit (t, "?", 1); + return (t->xmit (t, "?", 1) == 1) ? 0 : -1; } -static void +static int ansi_render (ANSI * a, CRT_CA ca) { + int err = 0; int dif; if ((ca.chr < VT102_CHARSET_SIZE) && (vt102_charset_c0[ca.chr])) @@ -415,9 +450,15 @@ ansi_render (ANSI * a, CRT_CA ca) ansi_set_color (a, ca.color); if (a->utf8) - utf8_emit (a->terminal, ca.chr); + { + if (utf8_emit (a->terminal, ca.chr)) + err++; + } else - ascii_emit (a->terminal, ca.chr); + { + if (ascii_emit (a->terminal, ca.chr)) + err++; + } a->pos.x++; @@ -427,111 +468,33 @@ ansi_render (ANSI * a, CRT_CA ca) if (a->pos.x >= a->size.x) a->pos.x = ANSI_INVAL; + return err; } -static void +static int ansi_cls (ANSI * a) { CRT_Pos p = { 0 }; + int err; crt_cls (&a->crt); - 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); + err += ansi_set_attr (a, CRT_ATTR_NORMAL); + err += ansi_set_color (a, CRT_COLOR_NORMAL); + err += ansi_move (a, p); + if (a->terminal->xmit (a->terminal, "\033[2J", 4) != 4) + err++; /*different emulators leave cursor in different places after cls differently*/ a->pos.x = ANSI_INVAL; -} - -#if 0 -int -ansi_scroll_up (ANSI * a, CRT_Pos s, CRT_Pos e) -{ - char buf[16]; - int i; - if (s.x) - return -1; - if (e.x != (CRT_COLS - 1)) - return -1; - if (s.y) - return -1; - if (s.y >= a->size.y) - return -1; - ansi_showhide_cursor (a, 1); - i = sprintf (buf, "\033[%d;%dr", s.y + 1, e.y + 1); - a->terminal->xmit (a->terminal, buf, i); - i = sprintf (buf, "\033[%d;%dH", e.y + 1, 0); - a->terminal->xmit (a->terminal, buf, i); - a->terminal->xmit (a->terminal, "\033D", 2); - a->terminal->xmit (a->terminal, "\033[r", 3); - - s.y = e.y; - crt_erase (&a->crt, s, e, 1); - - a->pos.x = ANSI_INVAL; - - return 0; -} - - -static void -ansi_spot_scroll_up (ANSI * a, CRT * c) -{ - int l, n, p; - - l = c->sh.e.x - c->sh.s.x; - l++; - l *= sizeof (CRT_CA); - - n = c->sh.e.y - c->sh.s.y; - p = CRT_ADDR_POS (&c->sh.s); - - while (n--) - { - if (memcmp (&c->screen[p], &a->crt.screen[p + CRT_COLS], l)) - return; - p += CRT_COLS; - } - - if (ansi_scroll_up (a, c->sh.s, c->sh.e)) - return; - - n = c->sh.e.y - c->sh.s.y; - p = CRT_ADDR_POS (&c->sh.s); - - while (n--) - { - memcpy (&a->crt.screen[p], &a->crt.screen[p + CRT_COLS], l); - p += CRT_COLS; - } - - c->sh.dir = 0; //FIXME: horrid hack - -} - -static void -ansi_spot_scroll (ANSI * a, CRT * c) -{ - - switch (c->sh.dir) - { - case -1: -/*we only care about up for the moment */ - ansi_spot_scroll_up (a, c); - break; - } - - return; + return err; } -#endif - - -static void +static int ansi_draw_line (ANSI * a, CRT_CA * cap, int y) { + int err = 0; + CRT_Pos p = { 0, y }; CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)]; @@ -542,21 +505,25 @@ ansi_draw_line (ANSI * a, CRT_CA * cap, int y) if (crt_ca_cmp (*acap, *cap)) { - ansi_showhide_cursor (a, 1); + err += ansi_showhide_cursor (a, 1); + *acap = *cap; - ansi_move (a, p); - ansi_render (a, *acap); + err += ansi_move (a, p); + err += ansi_render (a, *acap); } acap++; cap++; } + + return err; } -static void +static int ansi_resize_check (ANSI * a, CRT_Pos * size) { + int err = 0; if ((size && crt_pos_cmp (a->crt.size, *size)) || crt_pos_cmp (a->terminal->size, a->size)) @@ -580,48 +547,58 @@ ansi_resize_check (ANSI * a, CRT_Pos * size) // maybe - issue 132 column command if we're 132? 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); + if (a->terminal->xmit (a->terminal, "\033=", 2) != 2) + err++; + if (a->terminal->xmit (a->terminal, "\033[?6l", 5) != 5) + err++; + if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3) + err++; if (a->utf8) { - a->terminal->xmit (a->terminal, "\033%G", 3); + if (a->terminal->xmit (a->terminal, "\033%G", 3) != 3) + err++; } else { - a->terminal->xmit (a->terminal, "\033(B", 3); - a->terminal->xmit (a->terminal, "\033)0", 3); - a->terminal->xmit (a->terminal, "\017", 1); + if (a->terminal->xmit (a->terminal, "\033(B", 3) != 3) + err++; + if (a->terminal->xmit (a->terminal, "\033)0", 3) != 3) + err++; + if (a->terminal->xmit (a->terminal, "\017", 1) != 3) + err++; } } + return err; } -/*if they haven't then ansi_draw will patch it up*/ -static void +static int ansi_history (ANSI * a, History * h) { char buf[32]; int i; int guess_scroll; + int err = 0; /*Do we need to catch up on history?*/ if (a->history_ptr == h->wptr) - return; - ansi_resize_check (a, NULL); + return err; + + err += ansi_resize_check (a, NULL); if ((a->size.x < a->crt.size.x) || (a->size.y < a->crt.size.y)) - return; + return err; guess_scroll = a->crt.size.y - 1; /*Bototm line should be a status line */ - ansi_force_attr_normal (a); - ansi_set_color (a, CRT_COLOR_NORMAL); + err += ansi_force_attr_normal (a); + err += ansi_set_color (a, CRT_COLOR_NORMAL); i = sprintf (buf, "\033[%d;%dr", 1, guess_scroll); - a->terminal->xmit (a->terminal, buf, i); + if (a->terminal->xmit (a->terminal, buf, i) != i) + err++; while (a->history_ptr != h->wptr) @@ -635,19 +612,24 @@ ansi_history (ANSI * a, History * h) continue; /*If so write the line ot the top of the screen */ - ansi_draw_line (a, e->line, 0); + err += ansi_draw_line (a, e->line, 0); /*Roll guess_scroll lines up putting the top line into the xterm's history */ /*Make extra lines a predictable colour */ - ansi_set_color (a, CRT_COLOR_NORMAL); + err += ansi_set_color (a, CRT_COLOR_NORMAL); + + err += ansi_showhide_cursor (a, 1); - ansi_showhide_cursor (a, 1); i = sprintf (buf, "\033[%d;%dH", guess_scroll, 1); - a->terminal->xmit (a->terminal, buf, i); - a->terminal->xmit (a->terminal, "\033D", 2); + if (a->terminal->xmit (a->terminal, buf, i) != i) + err++; + + if (a->terminal->xmit (a->terminal, "\033D", 2) != 2) + err++; + a->pos.x = ANSI_INVAL; /*now do the same in our image of the screen */ @@ -674,22 +656,26 @@ ansi_history (ANSI * a, History * h) } /*reset margins*/ - a->terminal->xmit (a->terminal, "\033[r", 3); + if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3) + err++; + a->pos.x = ANSI_INVAL; + return err; } -static void +static int ansi_draw (ANSI * a, CRT * c) { CRT_Pos p; int o; int hidden_cursor = 0; + int err = 0; - ansi_resize_check (a, &c->size); + err += ansi_resize_check (a, &c->size); for (p.y = 0; p.y < a->crt.size.y; ++p.y) @@ -697,7 +683,7 @@ ansi_draw (ANSI * a, CRT * c) if (p.y >= a->size.y) continue; - ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y); + err += ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y); } @@ -713,34 +699,39 @@ ansi_draw (ANSI * a, CRT * c) sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x, a->size.y, c->size.x, c->size.y); - 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); + err += ansi_showhide_cursor (a, 1); + err += ansi_set_attr (a, CRT_ATTR_REVERSE); + err += + ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED)); + err += ansi_move (a, p); + + if (a->terminal->xmit (a->terminal, msg, i) != i) + err++; - a->terminal->xmit (a->terminal, msg, i); a->pos.x = ANSI_INVAL; } if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y)) { - ansi_showhide_cursor (a, 1); - return; + err += ansi_showhide_cursor (a, 1); + return err; } a->crt.pos = c->pos; - ansi_move (a, a->crt.pos); + err += ansi_move (a, a->crt.pos); a->crt.hide_cursor = c->hide_cursor; - ansi_showhide_cursor (a, a->crt.hide_cursor); + err += ansi_showhide_cursor (a, a->crt.hide_cursor); + + return err; } -static void +static int ansi_reset (ANSI * a, CRT * c) { a->size.x = -1; - ansi_draw (a, c ? c : &a->crt); + return ansi_draw (a, c ? c : &a->crt); } static void @@ -1004,12 +995,15 @@ ansi_dispatch (ANSI * a, Context * c) } -static void +static int ansi_update (ANSI * a, Context * c) { - ansi_history (a, c->h); - ansi_draw (a, &c->v->crt); + int err = 0; + + err += ansi_history (a, c->h); + err += ansi_draw (a, &c->v->crt); tty_length (a->terminal, c->v->crt.size.y); + return err; } static void @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.16 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.15 2008/03/03 06:04:42 james * *** empty log message *** * @@ -83,6 +86,8 @@ typedef struct ANSI_struct ANSI_Parser parser; TTY *terminal; + int eof; + CRT crt; CRT_Pos pos; @@ -97,9 +102,9 @@ typedef struct ANSI_struct FILE *file; int (*dispatch) (struct ANSI_struct *, struct Context_struct *); - void (*update) (struct ANSI_struct *, struct Context_struct *); - void (*one_shot) (struct ANSI_struct *, struct CRT_struct *); - void (*reset) (struct ANSI_struct *, struct CRT_struct *); + int (*update) (struct ANSI_struct *, struct Context_struct *); + int (*one_shot) (struct ANSI_struct *, struct CRT_struct *); + int (*reset) (struct ANSI_struct *, struct CRT_struct *); void (*terminal_reset) (struct ANSI_struct *); void (*close) (struct ANSI_struct *); } ANSI; diff --git a/src/context.h b/src/context.h index 33e9f2c..9245bf2 100644 --- a/src/context.h +++ b/src/context.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.11 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.10 2008/03/03 06:04:42 james * *** empty log message *** * @@ -57,6 +60,7 @@ typedef struct Context_struct KeyDis *k; Cmd *d; UTF8 *u; + RX *r; } Context; #endif /* __CONTEXT_H__ */ @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.12 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.11 2008/03/03 06:04:42 james * *** empty log message *** * @@ -189,10 +192,11 @@ html_draw (FILE * f, CRT * c) } -static void +static int html_one_shot (ANSI * a, CRT * c) { html_draw (a->file, c); +return 0; } diff --git a/src/prototypes.h b/src/prototypes.h index d640285..842b12b 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,184 +1,184 @@ /* ansi.c */ -extern int ansi_key (ANSI * a, Context * c, int key); -extern int ansi_dispatch (ANSI * a, Context * c); -extern ANSI *ansi_new_from_terminal (TTY * t, int utf8); +extern int ansi_key(ANSI *a, Context *c, int key); +extern int ansi_dispatch(ANSI *a, Context *c); +extern ANSI *ansi_new_from_terminal(TTY *t, int utf8); /* crt.c */ -extern void crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color); -extern void crt_cls (CRT * c); -extern void crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color); -extern void crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, - int color); -extern void crt_reset (CRT * c); -extern void crt_insert (CRT * c, CRT_CA ca); +extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color); +extern void crt_cls(CRT *c); +extern void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color); +extern void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color); +extern void crt_reset(CRT *c); +extern void crt_insert(CRT *c, CRT_CA ca); /* html.c */ -extern ANSI *ansi_new_html (FILE * f); +extern ANSI *ansi_new_html(FILE *f); /* libsympathy.c */ /* render.c */ /* version.c */ -extern char *libsympathy_version (void); +extern char *libsympathy_version(void); /* vt102.c */ extern int vt102_cmd_length[128]; extern int vt102_cmd_termination[128]; -extern void vt102_crt_update (Context * c); -extern void vt102_do_resize (Context * c); -extern void vt102_log_line (Context * c, int line); -extern void vt102_history (Context * c, CRT_Pos t, CRT_Pos b); -extern void vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br); -extern void vt102_cursor_normalize (VT102 * v); -extern void vt102_cursor_carriage_return (VT102 * v); -extern void vt102_cursor_advance_line (Context * c); -extern void vt102_cursor_retreat_line (Context * c); -extern void vt102_do_pending_wrap (Context * c); -extern void vt102_cursor_advance (Context * c); -extern void vt102_cursor_retreat (VT102 * v); -extern void vt102_reset_tabs (VT102 * v); -extern void vt102_cursor_advance_tab (VT102 * v); -extern void vt102_cursor_retreat_tab (VT102 * v); -extern int vt102_cursor_home (VT102 * v); -extern int vt102_cursor_absolute (VT102 * v, int x, int y); -extern int vt102_cursor_relative (VT102 * v, int x, int y); -extern void vt102_delete_from_line (VT102 * v, CRT_Pos p); -extern void vt102_insert_into_line (VT102 * v, CRT_Pos p); -extern void vt102_change_mode (Context * c, int private, char *ns, int set); -extern void vt102_parse_mode_string (Context * c, char *buf, int len); -extern void vt102_change_attr (VT102 * v, char *na); -extern void vt102_parse_attr_string (VT102 * v, char *buf, int len); -extern void vt102_save_state (VT102 * v); -extern void vt102_restore_state (VT102 * v); -extern void vt102_regular_char (Context * c, VT102 * v, uint32_t ch); -extern int vt102_send_id (Context * c, char *buf); -extern void vt102_scs (Context * c, int g, int s); -extern void vt102_parse_csi (Context * c, char *buf, int len); -extern void vt102_parse_esc (Context * c); -extern void vt102_status_line (VT102 * v, char *str); -extern void vt102_parser_reset (VT102_parser * p); -extern void vt102_reset_state (Context * c); -extern void vt102_parse_char (Context * c, int ch); -extern void vt102_send (Context * c, uint8_t key); -extern void vt102_reset (Context * c); -extern VT102 *vt102_new (CRT_Pos * size); -extern void vt102_set_ansi (VT102 * v, int ansi); -extern void vt102_resize (Context * c, CRT_Pos size); -extern void vt102_free (VT102 * v); +extern void vt102_crt_update(Context *c); +extern void vt102_do_resize(Context *c); +extern void vt102_log_line(Context *c, int line); +extern void vt102_history(Context *c, CRT_Pos t, CRT_Pos b); +extern void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br); +extern void vt102_cursor_normalize(VT102 *v); +extern void vt102_cursor_carriage_return(VT102 *v); +extern void vt102_cursor_advance_line(Context *c); +extern void vt102_cursor_retreat_line(Context *c); +extern void vt102_do_pending_wrap(Context *c); +extern void vt102_cursor_advance(Context *c); +extern void vt102_cursor_retreat(VT102 *v); +extern void vt102_reset_tabs(VT102 *v); +extern void vt102_cursor_advance_tab(VT102 *v); +extern void vt102_cursor_retreat_tab(VT102 *v); +extern int vt102_cursor_home(VT102 *v); +extern int vt102_cursor_absolute(VT102 *v, int x, int y); +extern int vt102_cursor_relative(VT102 *v, int x, int y); +extern void vt102_delete_from_line(VT102 *v, CRT_Pos p); +extern void vt102_insert_into_line(VT102 *v, CRT_Pos p); +extern void vt102_change_mode(Context *c, int private, char *ns, int set); +extern void vt102_parse_mode_string(Context *c, char *buf, int len); +extern void vt102_change_attr(VT102 *v, char *na); +extern void vt102_parse_attr_string(VT102 *v, char *buf, int len); +extern void vt102_save_state(VT102 *v); +extern void vt102_restore_state(VT102 *v); +extern void vt102_regular_char(Context *c, VT102 *v, uint32_t ch); +extern int vt102_send_id(Context *c, char *buf); +extern void vt102_scs(Context *c, int g, int s); +extern void vt102_parse_csi(Context *c, char *buf, int len); +extern void vt102_parse_esc(Context *c); +extern void vt102_status_line(VT102 *v, char *str); +extern void vt102_parser_reset(VT102_parser *p); +extern void vt102_reset_state(Context *c); +extern int vt102_rx_hook(Context *c, int ch); +extern int vt102_parse_char(Context *c, int ch); +extern void vt102_send(Context *c, uint8_t key); +extern void vt102_reset(Context *c); +extern VT102 *vt102_new(CRT_Pos *size); +extern void vt102_set_ansi(VT102 *v, int ansi); +extern void vt102_resize(Context *c, CRT_Pos size); +extern void vt102_free(VT102 *v); /* tty.c */ -extern void tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds); -extern int tty_get_status (TTY * t, TTY_Status * s); -extern int tty_get_baud (TTY * t); -extern void tty_set_baud (TTY * t, int rate); -extern void tty_send_break (TTY * t); -extern void tty_set_flow (TTY * t, int flow); -extern void tty_hangup (TTY * t); -extern void tty_length (TTY * t, int l); -extern void tty_winch (TTY * t, CRT_Pos size); -extern void tty_parse_reset (Context * c); -extern void tty_analyse (Context * c); -extern TTY_Parser *tty_parser_new (void); -extern void tty_parse (Context * c, uint8_t * buf, int len); +extern void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds); +extern int tty_get_status(TTY *t, TTY_Status *s); +extern int tty_get_baud(TTY *t); +extern void tty_set_baud(TTY *t, int rate); +extern void tty_send_break(TTY *t); +extern void tty_set_flow(TTY *t, int flow); +extern void tty_hangup(TTY *t); +extern void tty_length(TTY *t, int l); +extern void tty_winch(TTY *t, CRT_Pos size); +extern void tty_parse_reset(Context *c); +extern void tty_analyse(Context *c); +extern TTY_Parser *tty_parser_new(void); +extern int tty_parse(Context *c, uint8_t *buf, int len); /* keydis.c */ -extern KeyDis *keydis_vt102_new (void); -extern KeyDis *keydis_ipc_new (Socket * s); +extern KeyDis *keydis_vt102_new(void); +extern KeyDis *keydis_ipc_new(Socket *s); /* history.c */ -extern History *history_new (int n); -extern void history_free (History * h); -extern void history_add (History * h, CRT_CA * c); +extern History *history_new(int n); +extern void history_free(History *h); +extern void history_add(History *h, CRT_CA *c); /* ring.c */ -extern int ring_read (Ring * r, void *b, int n); -extern int ring_write (Ring * r, void *b, int n); -extern int ring_space (Ring * r); -extern int ring_bytes (Ring * r); -extern Ring *ring_new (int n); +extern int ring_read(Ring *r, void *b, int n); +extern int ring_write(Ring *r, void *b, int n); +extern int ring_space(Ring *r); +extern int ring_bytes(Ring *r); +extern Ring *ring_new(int n); /* ptty.c */ -extern TTY *ptty_open (char *path, char *argv[], CRT_Pos * size); +extern TTY *ptty_open(char *path, char *argv[], CRT_Pos *size); /* terminal.c */ extern int terminal_winches; -extern void terminal_atexit (void); -extern void terminal_getsize (TTY * _t); -extern void terminal_dispatch (void); -extern void terminal_register_handlers (void); -extern TTY *terminal_open (int rfd, int wfd); +extern void terminal_atexit(void); +extern void terminal_getsize(TTY *_t); +extern void terminal_dispatch(void); +extern void terminal_register_handlers(void); +extern TTY *terminal_open(int rfd, int wfd); /* util.c */ -extern int wrap_read (int fd, void *buf, int len); -extern int wrap_write (int fd, void *buf, int len); -extern void set_nonblocking (int fd); -extern void set_blocking (int fd); -extern void default_termios (struct termios *termios); -extern void client_termios (struct termios *termios); -extern int fput_cp (FILE * f, uint32_t ch); +extern int wrap_read(int fd, void *buf, int len); +extern int wrap_write(int fd, void *buf, int len); +extern void set_nonblocking(int fd); +extern void set_blocking(int fd); +extern void default_termios(struct termios *termios); +extern void client_termios(struct termios *termios); +extern int fput_cp(FILE *f, uint32_t ch); /* log.c */ -extern Log *file_log_new (char *fn, int rotate); -extern void log_f (Log * log, char *fmt, ...); +extern Log *file_log_new(char *fn, int rotate); +extern void log_f(Log *log, char *fmt, ...); /* ipc.c */ -extern IPC_Msg *ipc_check_for_message_in_slide (Slide * s); -extern void ipc_consume_message_in_slide (Slide * s); -extern int ipc_msg_send (Socket * s, IPC_Msg * m); -extern int ipc_msg_send_debug (Socket * s, char *msg); -extern int ipc_msg_send_history (Socket * s, History_ent * l); -extern int ipc_msg_send_vt102 (Socket * s, VT102 * v); -extern int ipc_msg_send_key (Socket * s, int key); -extern int ipc_msg_send_term (Socket * s, void *buf, int len); -extern int ipc_msg_send_status (Socket * s, char *buf); -extern int ipc_msg_send_setbaud (Socket * s, int baud); -extern int ipc_msg_send_sendbreak (Socket * s); -extern int ipc_msg_send_setflow (Socket * s, int flow); -extern int ipc_msg_send_setansi (Socket * s, int ansi); -extern int ipc_msg_send_hangup (Socket * s); -extern int ipc_msg_send_setsize (Socket * s, CRT_Pos size); -extern int ipc_msg_send_reset (Socket * s); -extern void ipc_execute_message (IPC_Msg * m, Context * c); +extern IPC_Msg *ipc_check_for_message_in_slide(Slide *s); +extern void ipc_consume_message_in_slide(Slide *s); +extern int ipc_msg_send(Socket *s, IPC_Msg *m); +extern int ipc_msg_send_debug(Socket *s, char *msg); +extern int ipc_msg_send_history(Socket *s, History_ent *l); +extern int ipc_msg_send_vt102(Socket *s, VT102 *v); +extern int ipc_msg_send_key(Socket *s, int key); +extern int ipc_msg_send_term(Socket *s, void *buf, int len); +extern int ipc_msg_send_status(Socket *s, char *buf); +extern int ipc_msg_send_setbaud(Socket *s, int baud); +extern int ipc_msg_send_sendbreak(Socket *s); +extern int ipc_msg_send_setflow(Socket *s, int flow); +extern int ipc_msg_send_setansi(Socket *s, int ansi); +extern int ipc_msg_send_hangup(Socket *s); +extern int ipc_msg_send_setsize(Socket *s, CRT_Pos size); +extern int ipc_msg_send_reset(Socket *s); +extern void ipc_execute_message(IPC_Msg *m, Context *c); /* slide.c */ -extern void slide_free (Slide * s); -extern void slide_consume (Slide * s, int n); -extern void slide_added (Slide * s, int n); -extern Slide *slide_new (int n); -extern void slide_expand (Slide * s, int n); +extern void slide_free(Slide *s); +extern void slide_consume(Slide *s, int n); +extern void slide_added(Slide *s, int n); +extern Slide *slide_new(int n); +extern void slide_expand(Slide *s, int n); /* symsocket.c */ -extern int wrap_recv (int fd, void *buf, int len); -extern int wrap_send (int fd, void *buf, int len); -extern void socket_free (Socket * s); -extern void socket_free_parent (Socket * s); -extern Socket *socket_listen (char *path); -extern Socket *socket_accept (Socket * l); -extern Socket *socket_connect (char *path); -extern void socket_consume_msg (Socket * s); -extern void socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds); -extern int socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds); -extern int socket_write (Socket * s, void *buf, int len); -extern void socket_execute_msg (Socket * s, Context * ctx); +extern int wrap_recv(int fd, void *buf, int len); +extern int wrap_send(int fd, void *buf, int len); +extern void socket_free(Socket *s); +extern void socket_free_parent(Socket *s); +extern Socket *socket_listen(char *path); +extern Socket *socket_accept(Socket *l); +extern Socket *socket_connect(char *path); +extern void socket_consume_msg(Socket *s); +extern void socket_pre_select(Socket *s, fd_set *rfds, fd_set *wfds); +extern int socket_post_select(Socket *s, fd_set *rfds, fd_set *wfds); +extern int socket_write(Socket *s, void *buf, int len); +extern void socket_execute_msg(Socket *s, Context *ctx); /* serial.c */ -extern TTY *serial_open (char *path, int lock_mode); +extern TTY *serial_open(char *path, int lock_mode); /* cmd.c */ -extern int cmd_parse (Cmd * c, Context * ctx, ANSI * a, char *buf); -extern void cmd_show_status (Cmd * c, Context * ctx); -extern int cmd_key (Cmd * c, Context * ctx, ANSI * a, int key); -extern int cmd_deactivate (Cmd * c, Context * ctx); -extern int cmd_activate (Cmd * c, Context * ctx); -extern void cmd_new_status (Cmd * c, Context * ctx, char *msg); -extern Cmd *cmd_new (void); +extern int cmd_parse(Cmd *c, Context *ctx, ANSI *a, char *buf); +extern void cmd_show_status(Cmd *c, Context *ctx); +extern int cmd_key(Cmd *c, Context *ctx, ANSI *a, int key); +extern int cmd_deactivate(Cmd *c, Context *ctx); +extern int cmd_activate(Cmd *c, Context *ctx); +extern void cmd_new_status(Cmd *c, Context *ctx, char *msg); +extern Cmd *cmd_new(void); /* lockfile.c */ -extern Filelist *filelist_new (void); -extern void filelist_remove (Filelist * fl, Filelist_ent * fle); -extern void filelist_add (Filelist * fl, char *fn); -extern void filelist_free (Filelist * fl); -extern void filelist_print (Filelist * fl, FILE * f); -extern int lockfile_make (char *name); -extern void lockfile_add_places (Filelist * fl, char *leaf); -extern void lockfile_regularize_and_add (Filelist * fl, char *leaf); -extern void lockfile_add_name_from_path (Filelist * fl, char *file); -extern void lockfile_add_name_from_dev (Filelist * fl, dev_t dev); -extern void lockfile_check_dir_for_dev (Filelist * fl, char *dir, dev_t dev); -extern Filelist *lockfile_make_list (char *device); -extern void lockfile_remove_stale (Filelist * fl); -extern Filelist *lockfile_lock (Filelist * fl); -extern void lockfile_unlock (Filelist * fl); -extern int serial_lock_check (Serial_lock * l); -extern void serial_lock_free (Serial_lock * l); -extern Serial_lock *serial_lock_new (char *dev, int mode); +extern Filelist *filelist_new(void); +extern void filelist_remove(Filelist *fl, Filelist_ent *fle); +extern void filelist_add(Filelist *fl, char *fn); +extern void filelist_free(Filelist *fl); +extern void filelist_print(Filelist *fl, FILE *f); +extern int lockfile_make(char *name); +extern void lockfile_add_places(Filelist *fl, char *leaf); +extern void lockfile_regularize_and_add(Filelist *fl, char *leaf); +extern void lockfile_add_name_from_path(Filelist *fl, char *file); +extern void lockfile_add_name_from_dev(Filelist *fl, dev_t dev); +extern void lockfile_check_dir_for_dev(Filelist *fl, char *dir, dev_t dev); +extern Filelist *lockfile_make_list(char *device); +extern void lockfile_remove_stale(Filelist *fl); +extern Filelist *lockfile_lock(Filelist *fl); +extern void lockfile_unlock(Filelist *fl); +extern int serial_lock_check(Serial_lock *l); +extern void serial_lock_free(Serial_lock *l); +extern Serial_lock *serial_lock_new(char *dev, int mode); /* utf8.c */ -extern void utf8_flush (Context * c); -extern void utf8_parse (Context * c, uint32_t ch); -extern UTF8 *utf8_new (void); -extern int utf8_encode (char *ptr, int ch); -extern void utf8_emit (TTY * t, int ch); +extern int utf8_flush(Context *c); +extern int utf8_parse(Context *c, uint32_t ch); +extern UTF8 *utf8_new(void); +extern int utf8_encode(char *ptr, int ch); +extern int utf8_emit(TTY *t, int ch); /* vt102_charset.c */ extern uint32_t vt102_charset_c0[128]; extern uint32_t vt102_charset_us[128]; @@ -187,6 +187,10 @@ extern uint32_t vt102_charset_vt52[128]; extern uint32_t vt102_charset_gl[128]; extern uint32_t *charset_from_csid[]; /* rotate.c */ -extern void rotate_gzip (char *file); -extern void rotate (char *file); -extern int rotate_check (char *file); +extern void rotate_gzip(char *file); +extern void rotate(char *file); +extern int rotate_check(char *file); +/* raw.c */ +extern RX *rx_new_raw(int rfd, int wfd); +extern TTY *terminal_new_raw(int rfd, int wfd); +extern ANSI *ansi_new_raw(int rfd, int wfd); diff --git a/src/raw.c b/src/raw.c new file mode 100644 index 0000000..5e6b586 --- /dev/null +++ b/src/raw.c @@ -0,0 +1,87 @@ +/* + * raw.c: + * + * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>, + * All rights reserved. + * + */ + +static char rcsid[] = "$Id$"; + +/* + * $Log$ + * Revision 1.1 2008/03/06 16:49:05 james + * *** empty log message *** + * + * + */ + +#include "project.h" + +typedef struct { + RX_SIGNATURE; + int rfd; + int wfd; +} RX_Raw; + +static int rx_raw_rx(RX *_r,int ch) +{ +RX_Raw *r=(RX_Raw *) _r; +uint8_t c=ch; +return (write(r->wfd,&c,1)==1) ? 0:-1; +} + +static void rx_raw_close(RX *r) +{ +free(r); +} + +RX *rx_new_raw(int rfd,int wfd) +{ + RX_Raw *ret; + + ret = malloc (sizeof (RX_Raw)); + memset (ret, 0, sizeof (RX_Raw)); + + ret->rx=rx_raw_rx; + ret->close=rx_raw_close; + + ret->rfd=rfd; + ret->wfd=wfd; + + return (RX*) ret; +} + + + +TTY *terminal_new_raw(int rfd,int wfd) +{ +//FIXME +return NULL; +} + +static void +ansi_raw_one_shot (ANSI * a, CRT * c) +{ +} + + +static void +ansi_raw_free (ANSI * a) +{ + free (a); +} + +ANSI * +ansi_new_raw (int rfd,int wfd) +{ + ANSI *ret; + + ret = malloc (sizeof (ANSI)); + memset (ret, 0, sizeof (ANSI)); + + ret->terminal = terminal_new_raw(rfd,wfd); + ret->close = ansi_raw_free; + + return ret; +} @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.2 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.1 2008/03/06 15:17:26 james * *** empty log message *** * @@ -20,10 +23,14 @@ #ifndef __RX_H__ #define __RX_H__ +#define RX_SIGNATURE \ + int (*rx)(struct RX_struct *,int); \ + void (*close)(struct RX_struct *); + typedef struct RX_struct { - void (*rx)(struct RX_struct *,int); + RX_SIGNATURE; } RX; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.22 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.21 2008/03/03 06:04:42 james * *** empty log message *** * @@ -525,10 +528,11 @@ tty_parser_new (void) return p; } -void +int tty_parse (Context * c, uint8_t * buf, int len) { TTY_Parser *p; + int err=0; p = c->tp; @@ -542,7 +546,7 @@ tty_parse (Context * c, uint8_t * buf, int len) { case DLE: tty_bit_analyse (c, 0, *buf); - utf8_parse (c, *buf); + err+=utf8_parse (c, *buf); break; case 0: p->in_errmark = 1; @@ -563,9 +567,9 @@ tty_parse (Context * c, uint8_t * buf, int len) tty_analyse (c); - utf8_parse (c, *buf); + err+=utf8_parse (c, *buf); - utf8_parse (c, SYM_CHAR_RESET); + err+=utf8_parse (c, SYM_CHAR_RESET); } else if (*buf == DLE) @@ -579,9 +583,10 @@ tty_parse (Context * c, uint8_t * buf, int len) tty_analyse (c); - utf8_parse (c, *buf); + err+=utf8_parse (c, *buf); } buf++; } +return err; } @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.12 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.11 2008/03/03 06:04:42 james * *** empty log message *** * @@ -48,11 +51,12 @@ static char rcsid[] = "$Id$"; #include "project.h" -void +int utf8_flush (Context * c) { UTF8 *u = c->u; int i; + int err=0; switch (u->utf_ptr) { @@ -75,31 +79,35 @@ utf8_flush (Context * c) } for (i = 0; i < u->utf_ptr; ++i) - vt102_parse_char (c, u->utf_buf[i]); + err+=vt102_parse_char (c, u->utf_buf[i]); u->utf_ptr = 0; u->in_utf8 = 0; + + return err; + } -void +int utf8_parse (Context * c, uint32_t ch) { UTF8 *u = c->u; + int err=0; if (ch == SYM_CHAR_RESET) { u->in_utf8 = 0; - vt102_parse_char (c, ch); - return; + err+=vt102_parse_char (c, ch); + return err; } if (!u->in_utf8) { /*FIXME: for the moment we bodge utf8 support - need to do */ /* L->R and R->L and double width characters */ - if (ch == 0xb9) + if (ch == 0xb9) //FIXME - OTHER 8 bit control chars { /*CSI, not a valid utf8 start char */ - vt102_parse_char (c, ch); + err+=vt102_parse_char (c, ch); } else if ((ch & 0xe0) == 0xc0) { /*Start of two byte unicode sequence */ @@ -127,15 +135,15 @@ utf8_parse (Context * c, uint32_t ch) } else { - vt102_parse_char (c, ch); + err+=vt102_parse_char (c, ch); } } else { if ((ch & 0xc0) != 0x80) { - utf8_flush (c); - vt102_parse_char (c, ch); + err+=utf8_flush (c); + err+=vt102_parse_char (c, ch); } else { @@ -145,9 +153,10 @@ utf8_parse (Context * c, uint32_t ch) u->in_utf8--; if (!u->in_utf8) - vt102_parse_char (c, u->ch); + err+=vt102_parse_char (c, u->ch); } } +return err; } @@ -196,14 +205,16 @@ utf8_encode (char *ptr, int ch) return 0; } -void +int utf8_emit (TTY * t, int ch) { uint8_t buf[4]; int i; i = utf8_encode (buf, ch); if (!i) - return; + return 0; - t->xmit (t, buf, i); + if (t->xmit (t, buf, i)!=i) + return -1; + return 0; } diff --git a/src/vt102.c b/src/vt102.c index 1b875da..4fd111d 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.59 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.58 2008/03/06 01:41:48 james * *** empty log message *** * @@ -1711,9 +1714,17 @@ pre_parse_cmd (int ch, VT102_parser * p) } } -void +int vt102_rx_hook(Context *c, int ch) +{ +if (!c->r) return 0; +if (!c->r->rx) return 0; +return c->r->rx(c->r,ch); +} + +int vt102_parse_char (Context * c, int ch) { + int err=0; VT102 *v = c->v; VT102_parser *p = &v->parser; @@ -1828,18 +1839,22 @@ vt102_parse_char (Context * c, int ch) break; /*BS*/ case 8: vt102_cursor_retreat (c->v); + err+=vt102_rx_hook(c,ch); break; /*HT*/ case 9: vt102_cursor_advance_tab (c->v); + err+=vt102_rx_hook(c,ch); break; /*LF*/ case 10: /*VT*/ case 11: /*FF*/ case 12: vt102_cursor_advance_line (c); + err+=vt102_rx_hook(c,10); if (!v->modes[VT102_MODE_NEWLINE_MODE]) break; /*CR*/ case 13: vt102_cursor_carriage_return (v); + err+=vt102_rx_hook(c,13); break; /*SO*/ case 14: /*select G1 */ @@ -1865,7 +1880,7 @@ vt102_parse_char (Context * c, int ch) #endif /*ESC*/ case 27: p->in_escape++; - return; + break; #if 0 /*FS*/ case 28: /*GS*/ case 29: @@ -1876,6 +1891,7 @@ vt102_parse_char (Context * c, int ch) #endif /*regular character */ default: vt102_regular_char (c, v, ch); + err+=vt102_rx_hook(c,ch); } #ifdef DEBUG @@ -1887,8 +1903,9 @@ vt102_parse_char (Context * c, int ch) vt102_crt_update (c); - +return err; } + void vt102_send (Context * c, uint8_t key) |