From f2c620137fa5290d913373e5579a97f0fee25fa3 Mon Sep 17 00:00:00 2001 From: james <> Date: Mon, 3 Mar 2008 06:04:42 +0000 Subject: *** empty log message *** --- apps/clients.c | 177 ++--- apps/clients.h | 9 +- apps/mainloop.c | 406 ++++++------ apps/mainloop.h | 7 +- apps/sympathy.c | 703 +++++++++++--------- apps/usage.c | 5 +- src/ansi.c | 716 +++++++++++--------- src/ansi.h | 9 +- src/cmd.c | 68 +- src/cmd.h | 8 +- src/context.h | 6 +- src/crt.c | 37 +- src/crt.h | 15 +- src/history.c | 12 +- src/history.h | 9 +- src/html.c | 101 +-- src/ipc.h | 51 +- src/keydis.c | 9 +- src/keydis.h | 6 +- src/lockfile.c | 235 ++++--- src/lockfile.h | 12 +- src/log.c | 80 ++- src/log.h | 6 +- src/prototypes.h | 309 ++++----- src/ptty.c | 77 ++- src/ring.c | 29 +- src/ring.h | 6 +- src/rotate.c | 6 +- src/serial.c | 66 +- src/slide.c | 12 +- src/slide.h | 6 +- src/symsocket.c | 96 +-- src/symsocket.h | 6 +- src/terminal.c | 65 +- src/tty.c | 386 ++++++----- src/tty.h | 12 +- src/utf8.c | 187 +++--- src/utf8.h | 6 +- src/vt102.c | 1942 ++++++++++++++++++++++++++++-------------------------- src/vt102.h | 12 +- sympathy.1 | 50 +- version-files | 1 + 42 files changed, 3314 insertions(+), 2647 deletions(-) diff --git a/apps/clients.c b/apps/clients.c index 4c4ea21..919f730 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.16 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.15 2008/03/02 10:27:24 james * *** empty log message *** * @@ -68,43 +71,44 @@ static char rcsid[] = "$Id$"; void client_msg (IPC_Msg * m, Context * c) { - switch (m->hdr.type) { - - case IPC_MSG_TYPE_NOOP: - break; - case IPC_MSG_TYPE_DEBUG: - fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg); - break; - case IPC_MSG_TYPE_KEY: - vt102_send (c, m->key.key); - break; - case IPC_MSG_TYPE_SETBAUD: - tty_set_baud (c->t, m->setbaud.baud); - tty_parse_reset (c); - - log_f (c->l, "", m->setbaud.baud); - break; - case IPC_MSG_TYPE_SENDBREAK: - tty_send_break (c->t); - break; - case IPC_MSG_TYPE_SETFLOW: - tty_set_flow (c->t, m->setflow.flow); - break; - case IPC_MSG_TYPE_SETANSI: - vt102_set_ansi (c->v, m->setansi.ansi); - break; - case IPC_MSG_TYPE_HANGUP: - tty_hangup (c->t); - break; - case IPC_MSG_TYPE_SETSIZE: - vt102_resize (c, m->setsize.winsize); - break; - case IPC_MSG_TYPE_RESET: - vt102_reset (c); - break; - default: - fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); - } + switch (m->hdr.type) + { + + case IPC_MSG_TYPE_NOOP: + break; + case IPC_MSG_TYPE_DEBUG: + fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg); + break; + case IPC_MSG_TYPE_KEY: + vt102_send (c, m->key.key); + break; + case IPC_MSG_TYPE_SETBAUD: + tty_set_baud (c->t, m->setbaud.baud); + tty_parse_reset (c); + + log_f (c->l, "", m->setbaud.baud); + break; + case IPC_MSG_TYPE_SENDBREAK: + tty_send_break (c->t); + break; + case IPC_MSG_TYPE_SETFLOW: + tty_set_flow (c->t, m->setflow.flow); + break; + case IPC_MSG_TYPE_SETANSI: + vt102_set_ansi (c->v, m->setansi.ansi); + break; + case IPC_MSG_TYPE_HANGUP: + tty_hangup (c->t); + break; + case IPC_MSG_TYPE_SETSIZE: + vt102_resize (c, m->setsize.winsize); + break; + case IPC_MSG_TYPE_RESET: + vt102_reset (c); + break; + default: + fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); + } } void @@ -150,17 +154,21 @@ clients_reap (Clients * cs) Client **p, *c; - for (p = &cs->head; *p;) { - Client *c = *p; - - if (c->dead) { - *p = c->next; - client_free (c); - cs->n--; - } else { - p = &(c->next); + for (p = &cs->head; *p;) + { + Client *c = *p; + + if (c->dead) + { + *p = c->next; + client_free (c); + cs->n--; + } + else + { + p = &(c->next); + } } - } } Clients * @@ -179,9 +187,10 @@ clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds) { Client *c; - for (c = cs->head; c; c = c->next) { - socket_pre_select (c->s, rfds, wfds); - } + for (c = cs->head; c; c = c->next) + { + socket_pre_select (c->s, rfds, wfds); + } } void @@ -191,18 +200,21 @@ clients_post_select (Clients * cs, Context * ctx, fd_set * rfds, Client *c; int deaded = 0; - for (c = cs->head; c; c = c->next) { - if (socket_post_select (c->s, rfds, wfds)) { - c->dead++; - deaded++; - } + for (c = cs->head; c; c = c->next) + { + if (socket_post_select (c->s, rfds, wfds)) + { + c->dead++; + deaded++; + } - if (c->s->msg) { - client_msg (c->s->msg, ctx); - socket_consume_msg (c->s); - } + if (c->s->msg) + { + client_msg (c->s->msg, ctx); + socket_consume_msg (c->s); + } - } + } if (deaded) clients_reap (cs); @@ -214,9 +226,10 @@ clients_shutdown (Clients * cs) { Client *c; - for (c = cs->head; c; c = c->next) { - c->dead++; - } + for (c = cs->head; c; c = c->next) + { + c->dead++; + } clients_reap (cs); @@ -250,11 +263,12 @@ send_status (Clients * cs, char *msg) strncpy (m->status, msg, IPC_MAX_BUF); m->status[IPC_MAX_BUF - 1] = 0; - for (c = cs->head; c; c = c->next) { - if (!c->dead) - if (ipc_msg_send (c->s, (IPC_Msg *) m)) - c->dead++; - } + for (c = cs->head; c; c = c->next) + { + if (!c->dead) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; + } return len; } @@ -278,11 +292,12 @@ send_output (Clients * cs, void *buf, int len) m->len = len; memcpy (m->term, buf, len); - for (c = cs->head; c; c = c->next) { - if (!c->dead) - if (ipc_msg_send (c->s, (IPC_Msg *) m)) - c->dead++; - } + for (c = cs->head; c; c = c->next) + { + if (!c->dead) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; + } return len; @@ -296,16 +311,18 @@ send_history (History * h, Client * c) HISTORY_INC (h, rptr); HISTORY_INC (h, rptr); - while (rptr != h->wptr) { - History_ent *l = &h->lines[rptr]; - if (l->valid) { + while (rptr != h->wptr) + { + History_ent *l = &h->lines[rptr]; + if (l->valid) + { - if (ipc_msg_send_history (c->s, l)) - c->dead++; + if (ipc_msg_send_history (c->s, l)) + c->dead++; + } + HISTORY_INC (h, rptr); } - HISTORY_INC (h, rptr); - } } void diff --git a/apps/clients.h b/apps/clients.h index c233e5f..3396f5c 100644 --- a/apps/clients.h +++ b/apps/clients.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.7 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.6 2008/03/02 10:27:24 james * *** empty log message *** * @@ -35,13 +38,15 @@ #ifndef __CLIENTS_H__ #define __CLIENTS_H__ -typedef struct Client_struct { +typedef struct Client_struct +{ struct Client_struct *next; Socket *s; int dead; } Client; -typedef struct { +typedef struct +{ Client *head; int n; } Clients; diff --git a/apps/mainloop.c b/apps/mainloop.c index 25718c4..dd553e3 100644 --- a/apps/mainloop.c +++ b/apps/mainloop.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.22 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.21 2008/03/02 10:27:24 james * *** empty log message *** * @@ -120,7 +123,8 @@ static char rcsid[] = Context *context; -typedef struct { +typedef struct +{ int nclients; int lines; int baud; @@ -157,10 +161,11 @@ get_status (TTY * t, Clients * cs) cd = (tty_status.lines & TIOCM_CD) ? 1 : 0; - if (cd != last_cd_state) { - gettimeofday (&last_cd_edge, NULL); - last_cd_state = cd; - } + if (cd != last_cd_state) + { + gettimeofday (&last_cd_edge, NULL); + last_cd_state = cd; + } gettimeofday (&now, NULL); timersub (&now, &last_cd_edge, &dif); @@ -173,44 +178,45 @@ static char * line_to_name (int l) { - switch (l) { + switch (l) + { #ifdef TIOCM_LE - case TIOCM_LE: - return "LE"; + case TIOCM_LE: + return "LE"; #endif #ifdef TIOCM_DTR - case TIOCM_DTR: - return "DTR"; + case TIOCM_DTR: + return "DTR"; #endif #ifdef TIOCM_RTS - case TIOCM_RTS: - return "RTS"; + case TIOCM_RTS: + return "RTS"; #endif #ifdef TIOCM_ST - case TIOCM_ST: - return "ST"; + case TIOCM_ST: + return "ST"; #endif #ifdef TIOCM_SR - case TIOCM_SR: - return "SR"; + case TIOCM_SR: + return "SR"; #endif #ifdef TIOCM_CTS - case TIOCM_CTS: - return "CTS"; + case TIOCM_CTS: + return "CTS"; #endif #ifdef TIOCM_CD - case TIOCM_CD: - return "CD"; + case TIOCM_CD: + return "CD"; #endif #ifdef TIOCM_RI - case TIOCM_RI: - return "RI"; + case TIOCM_RI: + return "RI"; #endif #ifdef TIOCM_DSR - case TIOCM_DSR: - return "DSR"; + case TIOCM_DSR: + return "DSR"; #endif - } + } return "??"; } @@ -232,18 +238,20 @@ log_line_changes (Context * ctx, int old, int new) while (*n) *(ptr++) = *(n++); - while (dif >= c) { + while (dif >= c) + { - if (dif & c) { - *(ptr++) = ' '; - *(ptr++) = (new & c) ? '+' : '-'; - n = line_to_name (c); - while (*n) - *(ptr++) = *(n++); - } + if (dif & c) + { + *(ptr++) = ' '; + *(ptr++) = (new & c) ? '+' : '-'; + n = line_to_name (c); + while (*n) + *(ptr++) = *(n++); + } - c <<= 1; - } + c <<= 1; + } *(ptr++) = '>'; *ptr = 0; @@ -304,45 +312,54 @@ check_status (Context * c, Clients * cs) ptr = do_line (ptr, status.lines, TIOCM_RI); ptr = do_line (ptr, status.lines, TIOCM_CD); - if (status.blocked) { - t = ", Locked"; - while (*t) - *(ptr++) = *(t++); - } - - if (status.crtscts) { - t = ", Flow"; - while (*t) - *(ptr++) = *(t++); - } + if (status.blocked) + { + t = ", Locked"; + while (*t) + *(ptr++) = *(t++); + } + + if (status.crtscts) + { + t = ", Flow"; + while (*t) + *(ptr++) = *(t++); + } #if 0 - if (status.lines & TIOCM_CD) { - ptr += - sprintf (ptr, ", On %d.%d", status.cd_edge_sec / 60, - status.cd_edge_sec % 60); - } else { - ptr += - sprintf (ptr, ", Off %d.%d", status.cd_edge_sec / 60, - status.cd_edge_sec % 60); - } + if (status.lines & TIOCM_CD) + { + ptr += + sprintf (ptr, ", On %d.%d", status.cd_edge_sec / 60, + status.cd_edge_sec % 60); + } + else + { + ptr += + sprintf (ptr, ", Off %d.%d", status.cd_edge_sec / 60, + status.cd_edge_sec % 60); + } #endif ptr += sprintf (ptr, ", %d client%s", status.nclients, (status.nclients == 1) ? "" : "s"); - if (c->tp->biterrs) { + if (c->tp->biterrs) + { - ptr += - sprintf (ptr, ", %d err%s", c->tp->biterrs, - (c->tp->biterrs == 1) ? "" : "s"); + ptr += + sprintf (ptr, ", %d err%s", c->tp->biterrs, + (c->tp->biterrs == 1) ? "" : "s"); - if (c->tp->guessed_baud == -1) { - ptr += sprintf (ptr, " try higher"); - } else if (c->tp->guessed_baud > 0) { - ptr += sprintf (ptr, " try %db", c->tp->guessed_baud); + if (c->tp->guessed_baud == -1) + { + ptr += sprintf (ptr, " try higher"); + } + else if (c->tp->guessed_baud > 0) + { + ptr += sprintf (ptr, " try %db", c->tp->guessed_baud); + } } - } *ptr = 0; @@ -361,36 +378,38 @@ check_status (Context * c, Clients * cs) static int msg_from_server (ANSI * a, IPC_Msg * m, Context * c) { - switch (m->hdr.type) { + switch (m->hdr.type) + { - case IPC_MSG_TYPE_NOOP: - break; - case IPC_MSG_TYPE_DEBUG: + case IPC_MSG_TYPE_NOOP: + break; + case IPC_MSG_TYPE_DEBUG: // fprintf (stderr,"%p [%d] %s\n", m, m->hdr.size , m->debug.msg ); - break; - case IPC_MSG_TYPE_HISTORY: - history_add (c->h, m->history.history.line); - break; - case IPC_MSG_TYPE_VT102: - if (sizeof (VT102) != m->vt102.len) - abort (); - - *(c->v) = m->vt102.vt102; - - if (a->one_shot) { - a->one_shot (a, &c->v->crt); - return 1; + break; + case IPC_MSG_TYPE_HISTORY: + history_add (c->h, m->history.history.line); + break; + case IPC_MSG_TYPE_VT102: + if (sizeof (VT102) != m->vt102.len) + abort (); + + *(c->v) = m->vt102.vt102; + + if (a->one_shot) + { + a->one_shot (a, &c->v->crt); + return 1; + } + break; + case IPC_MSG_TYPE_TERM: + tty_parse (c, m->term.term, m->term.len); + break; + case IPC_MSG_TYPE_STATUS: + cmd_new_status (c->d, c, m->status.status); + break; + default: + fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); } - break; - case IPC_MSG_TYPE_TERM: - tty_parse (c, m->term.term, m->term.len); - break; - case IPC_MSG_TYPE_STATUS: - cmd_new_status (c->d, c, m->status.status); - break; - default: - fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); - } return 0; } @@ -412,130 +431,149 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, 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); - } else { - if (!tty) - abort (); - c.t = tty; - c.k = keydis_vt102_new (); - } + if (client_socket) + { + if (server_socket) + abort (); + c.k = keydis_ipc_new (client_socket); + } + else + { + if (!tty) + abort (); + c.t = tty; + 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 (); - } else { - c.d = NULL; - } + if (ansi) + { + c.d = cmd_new (); + } + else + { + c.d = NULL; + } vt102_reset (&c); - if (server_socket) { - if (client_socket) - abort (); - clients = clients_new (); - } else { - clients = NULL; - } + if (server_socket) + { + if (client_socket) + abort (); + clients = clients_new (); + } + else + { + clients = NULL; + } - for (;;) { - struct timeval tv = { 0, 250000 }; + for (;;) + { + struct timeval tv = { 0, 250000 }; - if ((c.d) && (c.d->disconnect)) - break; + if ((c.d) && (c.d->disconnect)) + break; - /*update the status lines, locally or remotely */ - if (c.t) - check_status (&c, clients); + /*update the status lines, locally or remotely */ + if (c.t) + check_status (&c, clients); - FD_ZERO (&rfds); - FD_ZERO (&wfds); + 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) { - FD_SET (server_socket->fd, &rfds); - clients_pre_select (clients, &rfds, &wfds); - } + if (server_socket) + { + FD_SET (server_socket->fd, &rfds); + clients_pre_select (clients, &rfds, &wfds); + } - if (client_socket) - socket_pre_select (client_socket, &rfds, &wfds); + if (client_socket) + socket_pre_select (client_socket, &rfds, &wfds); - if (ansi && ansi->terminal) - tty_pre_select (ansi->terminal, &rfds, &wfds); + if (ansi && ansi->terminal) + tty_pre_select (ansi->terminal, &rfds, &wfds); - select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); + select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); - /*any message from clients, or new connexions */ - if (server_socket) { - Socket *new_client_socket; - if (FD_ISSET (server_socket->fd, &rfds) - && ((new_client_socket = socket_accept (server_socket)))) { + /*any message from clients, or new connexions */ + if (server_socket) { - Client *new_client; - /*New client connexion */ - new_client = clients_new_client (clients, new_client_socket, &c); - - send_history (c.h, new_client); - send_vt102 (c.v, new_client); - + Socket *new_client_socket; + if (FD_ISSET (server_socket->fd, &rfds) + && ((new_client_socket = socket_accept (server_socket)))) + { + { + Client *new_client; + /*New client connexion */ + new_client = + clients_new_client (clients, new_client_socket, &c); + + 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)) { - char buf[IPC_MAX_BUF]; - int red; - - red = c.t->recv (c.t, buf, sizeof (buf)); + /*any data from the port */ + if (c.t && FD_ISSET (c.t->rfd, &rfds)) + { + char buf[IPC_MAX_BUF]; + int red; - if (red < 0) - break; + red = c.t->recv (c.t, buf, sizeof (buf)); - if (red) { - if (clients) - send_output (clients, buf, red); - tty_parse (&c, buf, red); - } - } + if (red < 0) + break; + if (red) + { + if (clients) + send_output (clients, buf, red); + tty_parse (&c, buf, red); + } + } - /*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++; - - socket_consume_msg (client_socket); - } - if (one_shot) - break; - } + /*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++; + + socket_consume_msg (client_socket); + } + if (one_shot) + break; + } - /*update our local screen */ - if (ansi) { - if (ansi->dispatch) - ansi->dispatch (ansi, &c); + /*update our local screen */ + if (ansi) + { + if (ansi->dispatch) + ansi->dispatch (ansi, &c); - if (ansi->update) - ansi->update (ansi, &c); + if (ansi->update) + ansi->update (ansi, &c); + } } - } if (clients) clients_shutdown (clients); diff --git a/apps/mainloop.h b/apps/mainloop.h index 760cd9f..418b641 100644 --- a/apps/mainloop.h +++ b/apps/mainloop.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.7 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.6 2008/03/02 10:27:24 james * *** empty log message *** * @@ -38,7 +41,7 @@ #include extern void - mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, ANSI * a, - Log * log, int nhistory, CRT_Pos * size); +mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, ANSI * a, + Log * log, int nhistory, CRT_Pos * size); #endif /* __MAINLOOP_H__ */ diff --git a/apps/sympathy.c b/apps/sympathy.c index ff3a8bc..f5ed2e0 100644 --- a/apps/sympathy.c +++ b/apps/sympathy.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.32 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.31 2008/03/03 06:04:18 james * *** empty log message *** * @@ -160,15 +163,18 @@ fatal_moan (char *fmt, ...) exit (1); } -static void sigchld(int dummy) +static void +sigchld (int dummy) { -int status; - wait3(&status,WNOHANG,NULL); + int status; + wait3 (&status, WNOHANG, NULL); } /*Dispell zombies, from for example log compression*/ -void garlic(void) { -struct sigaction sa; +void +garlic (void) +{ + struct sigaction sa; sa.sa_handler = sigchld; sa.sa_flags = SA_RESTART; @@ -186,25 +192,26 @@ teedious_snprintf (char *fmt, va_list ap) if (!buf) fatal_moan ("malloc failed"); - while (1) { + while (1) + { - va_copy (aq, ap); - n = vsnprintf (buf, size, fmt, aq); - va_end (aq); + va_copy (aq, ap); + n = vsnprintf (buf, size, fmt, aq); + va_end (aq); - if (n > -1 && n < (size)) - return buf; + if (n > -1 && n < (size)) + return buf; - if (n > -1) /* glibc 2.1 */ - size = n + 1; - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ + if (n > -1) /* glibc 2.1 */ + size = n + 1; + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ - buf = realloc (buf, size); + buf = realloc (buf, size); - if (!buf) - fatal_moan ("malloc failed"); - } + if (!buf) + fatal_moan ("malloc failed"); + } } @@ -242,13 +249,16 @@ mome (char *fmt, ...) if (!home) return NULL; - if (fmt) { - va_start (ap, fmt); - leaf = teedious_snprintf (fmt, ap); - va_end (ap); - } else { - leaf = NULL; - } + if (fmt) + { + va_start (ap, fmt); + leaf = teedious_snprintf (fmt, ap); + va_end (ap); + } + else + { + leaf = NULL; + } ret = gloo_paths (home, leaf); if (leaf) @@ -266,40 +276,48 @@ find_socket (char *fmt, ...) va_list ap; - if (fmt) { - va_start (ap, fmt); - leaf = teedious_snprintf (fmt, ap); - va_end (ap); - } else { - leaf = NULL; - } + if (fmt) + { + va_start (ap, fmt); + leaf = teedious_snprintf (fmt, ap); + va_end (ap); + } + else + { + leaf = NULL; + } - for (ptr = socket_dirs; *ptr; ptr++) { - if (**ptr == '~') { - h = mome (*ptr + 1); - } else { - h = *ptr; - } + for (ptr = socket_dirs; *ptr; ptr++) + { + if (**ptr == '~') + { + h = mome (*ptr + 1); + } + else + { + h = *ptr; + } - if (!h) - continue; + if (!h) + continue; - path = gloo_paths (h, leaf); - if (**ptr == '~') - free (h); + path = gloo_paths (h, leaf); + if (**ptr == '~') + free (h); - ret = socket_connect (path); + ret = socket_connect (path); - free (path); + free (path); - if (ret) { - free (leaf); - return ret; - } + if (ret) + { + free (leaf); + return ret; + } - } + } free (leaf); return NULL; @@ -327,30 +345,38 @@ list_sockets_in_dir (char *sockdir) rewinddir (dir); - while ((ent = readdir (dir))) { - sn = gloo_paths (sockdir, ent->d_name); - if (stat (sn, &buf) || (!S_ISSOCK (buf.st_mode))) { - free (sn); - continue; - } + while ((ent = readdir (dir))) + { + sn = gloo_paths (sockdir, ent->d_name); + if (stat (sn, &buf) || (!S_ISSOCK (buf.st_mode))) + { + free (sn); + continue; + } + + s = socket_connect (sn); + + if (s) + { + printf ("\t%s (Active)\n", sn); + socket_free (s); + } + else + { + if (strncmp (ent->d_name, hostname, hostname_len)) + { + printf ("\t%s (Unknown - not this host)\n", sn); + } + else + { + printf ("\t%s (Dead, wiped)\n", sn); + unlink (sn); + } + } - s = socket_connect (sn); - - if (s) { - printf ("\t%s (Active)\n", sn); - socket_free (s); - } else { - if (strncmp (ent->d_name, hostname, hostname_len)) { - printf ("\t%s (Unknown - not this host)\n", sn); - } else { - printf ("\t%s (Dead, wiped)\n", sn); - unlink (sn); - } + free (sn); } - free (sn); - } - closedir (dir); return 0; @@ -362,22 +388,26 @@ list_sockets (void) char **ptr, *h; - for (ptr = socket_dirs; *ptr; ptr++) { - if (**ptr == '~') { - h = mome (*ptr + 1); - } else { - h = *ptr; - } + for (ptr = socket_dirs; *ptr; ptr++) + { + if (**ptr == '~') + { + h = mome (*ptr + 1); + } + else + { + h = *ptr; + } - if (!h) - continue; + if (!h) + continue; - list_sockets_in_dir (h); + list_sockets_in_dir (h); - if (**ptr == '~') - free (h); + if (**ptr == '~') + free (h); - } + } return 0; } @@ -388,10 +418,11 @@ get_hostname (void) { struct utsname name; - if (uname (&name)) { - strcpy (hostname, "unknown."); - return; - } + if (uname (&name)) + { + strcpy (hostname, "unknown."); + return; + } strcpy (hostname, name.nodename); @@ -421,32 +452,39 @@ main (int argc, char *argv[]) int history = 200; int pid; - char *pid_file=NULL; + char *pid_file = NULL; get_hostname (); memset (oflags, 0, sizeof (oflags)); memset (oargs, 0, sizeof (oargs)); - while ((c = getopt (argc, argv, "RP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF) { - switch (c) { - case ':': - case 'h': - case '?': - usage (); - default: - if ((c > 64) && (c < 91)) { - oflags[c]++; - oargs[c] = optarg; - } else if ((c > 96) && (c < 123)) { - oflags[c]++; - oargs[c] = optarg; - } else { - fprintf (stderr, "unknown option %c\n", c); - usage (); - } - } + while ((c = getopt (argc, argv, "RP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF) + { + switch (c) + { + case ':': + case 'h': + case '?': + usage (); + default: + if ((c > 64) && (c < 91)) + { + oflags[c]++; + oargs[c] = optarg; + } + else if ((c > 96) && (c < 123)) + { + oflags[c]++; + oargs[c] = optarg; + } + else + { + fprintf (stderr, "unknown option %c\n", c); + usage (); + } + } - } + } /*Compatability for screen's ls */ if (oflags['l']) @@ -461,23 +499,25 @@ main (int argc, char *argv[]) sum += oflags['l']; sum += oflags['v']; - if (!sum) { - /*If no mode is specified behave like screen */ - oflags['s']++; - oflags['c']++; - sum++; - } + if (!sum) + { + /*If no mode is specified behave like screen */ + oflags['s']++; + oflags['c']++; + sum++; + } if (sum != 1) fatal_moan ("specifiy exactly one of ( -c and or -s ), -t, -r, -l and -v"); } - if (oflags['v']) { - fprintf (stderr, "Version: %s\n", libsympathy_version ()); - fprintf (stderr, "Version: %s\n", rcsid); - return 0; - } + if (oflags['v']) + { + fprintf (stderr, "Version: %s\n", libsympathy_version ()); + fprintf (stderr, "Version: %s\n", rcsid); + return 0; + } if (oflags['l']) return list_sockets (); @@ -487,14 +527,15 @@ main (int argc, char *argv[]) fatal_moan ("-k is incompatible with -r"); - if (oflags['n']) { - history = safe_atoi (oargs['n']); - if (history < 0) - fatal_moan ("cannot parse -n %s as an integer", oargs['n']); + if (oflags['n']) + { + history = safe_atoi (oargs['n']); + if (history < 0) + fatal_moan ("cannot parse -n %s as an integer", oargs['n']); - if (!history) - fatal_moan ("agrument to -n must be greater than zero"); - } + if (!history) + fatal_moan ("agrument to -n must be greater than zero"); + } /*Fold -r implies -c */ if (oflags['r']) @@ -512,56 +553,60 @@ main (int argc, char *argv[]) /*server. If there's no -k argument the client (parent) needs */ /*to find out the pid of the server, we use a pipe */ - if (oflags['s'] && oflags['c']) { - if (!oflags['k']) { - csnok++; - pipe (csnok_pipe); - } - - switch (pid = fork ()) { - case 0: /*child becomes the server */ - oflags['c'] = 0; - oflags['H'] = 0; - - if (csnok) - close (csnok_pipe[0]); - break; - case -1: - fatal_moan ("fork failed"); - default: /*parent becomes client */ - oflags['s'] = 0; - oflags['K'] = 0; - oflags['d'] = 0; - oflags['p'] = 0; - oflags['b'] = 0; - oflags['f'] = 0; - oflags['L'] = 0; - oflags['R'] = 0; - oflags['P'] = 0; - oflags['n'] = 0; - oflags['w'] = 0; - - /*Collect the child */ - waitpid (pid, NULL, 0); - - /*if there was no k argument we need to find the */ - /*pid of the server process so that we can work out */ - /*what the socket is called. The server tells us on */ - /*a pipe */ - - if (csnok) { - close (csnok_pipe[1]); - - if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid)) - fatal_moan ("Failed to receive pid of server process"); - - close (csnok_pipe[0]); - - oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); - oflags['k']++; - } + if (oflags['s'] && oflags['c']) + { + if (!oflags['k']) + { + csnok++; + pipe (csnok_pipe); + } + + switch (pid = fork ()) + { + case 0: /*child becomes the server */ + oflags['c'] = 0; + oflags['H'] = 0; + + if (csnok) + close (csnok_pipe[0]); + break; + case -1: + fatal_moan ("fork failed"); + default: /*parent becomes client */ + oflags['s'] = 0; + oflags['K'] = 0; + oflags['d'] = 0; + oflags['p'] = 0; + oflags['b'] = 0; + oflags['f'] = 0; + oflags['L'] = 0; + oflags['R'] = 0; + oflags['P'] = 0; + oflags['n'] = 0; + oflags['w'] = 0; + + /*Collect the child */ + waitpid (pid, NULL, 0); + + /*if there was no k argument we need to find the */ + /*pid of the server process so that we can work out */ + /*what the socket is called. The server tells us on */ + /*a pipe */ + + if (csnok) + { + close (csnok_pipe[1]); + + if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid)) + fatal_moan ("Failed to receive pid of server process"); + + close (csnok_pipe[0]); + + oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); + oflags['k']++; + } + } } - } if (oflags['c'] && !oflags['k'] && !oflags['r']) @@ -569,179 +614,209 @@ main (int argc, char *argv[]) if ((oflags['p'] || oflags['d'] || oflags['K'] || oflags['b'] || oflags['f'] || oflags['L'] || oflags['R'] || oflags['P']) && oflags['c']) - fatal_moan ("-c or -r are incompatible with -p, -d, -K, -b, -f, -R, -P or -L"); + fatal_moan + ("-c or -r are incompatible with -p, -d, -K, -b, -f, -R, -P or -L"); - if (oflags['t'] || oflags['s']) { - if (!oflags['p'] && !oflags['d']) - oflags['p']++; - } - - if (oflags['w']) { - char buf[128], *ptr; - strcpy (buf, oargs['w']); - ptr = index (buf, 'x'); - if (ptr) { - *ptr = 0; - ptr++; - size.y = safe_atoi (ptr); + if (oflags['t'] || oflags['s']) + { + if (!oflags['p'] && !oflags['d']) + oflags['p']++; } - size.x = safe_atoi (buf); - - if ((size.x > VT102_MAX_COLS) || (size.x < 1)) - fatal_moan ("-w requires a width between 1 and %d\n", VT102_MAX_COLS); - - if ((size.y > VT102_MAX_ROWS) || (size.y < 1)) - fatal_moan ("-w requires a height between 1 and %d\n", VT102_MAX_ROWS); - - } - - if (oflags['s'] && !oflags['F']) { - /*nochdir incase socket is relative path, unlink then will fail */ - daemon (1, 0); - - } - - if (oflags['s']) { - char *path; - path = mome ("/.sympathy"); - mkdir (path, 0700); - free (path); + if (oflags['w']) + { + char buf[128], *ptr; + strcpy (buf, oargs['w']); + ptr = index (buf, 'x'); + if (ptr) + { + *ptr = 0; + ptr++; + size.y = safe_atoi (ptr); + } + size.x = safe_atoi (buf); + + if ((size.x > VT102_MAX_COLS) || (size.x < 1)) + fatal_moan ("-w requires a width between 1 and %d\n", VT102_MAX_COLS); + + if ((size.y > VT102_MAX_ROWS) || (size.y < 1)) + fatal_moan ("-w requires a height between 1 and %d\n", + VT102_MAX_ROWS); - - if (!oflags['k']) { - pid = getpid (); - - oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); - oflags['k']++; } - server_socket = socket_listen (oargs['k']); - - /*Tell our parent's parent what our pid is */ - if (csnok) { - pid = getpid (); + if (oflags['s'] && !oflags['F']) + { + /*nochdir incase socket is relative path, unlink then will fail */ + daemon (1, 0); - write (csnok_pipe[1], &pid, sizeof (pid)); - close (csnok_pipe[1]); } - if (!server_socket) - fatal_moan ("failed to create socket %s for listening", oargs['k']); - - } - - if (oflags['s'] || oflags['t']) { - if (oflags['P']) { - FILE *fp; - pid_file=oargs['P']; - fp=fopen(pid_file,"w"); - if (fp) { - fprintf(fp,"%d",getpid()); - fclose(fp); - } - } - if (oflags['L']) { - log = file_log_new (oargs['L'], oflags['R']); - if (!log) - fatal_moan ("unable to access log file %s", oargs['L']); - } + if (oflags['s']) + { + char *path; + path = mome ("/.sympathy"); + mkdir (path, 0700); + free (path); - if (oflags['p']) { - tty = ptty_open (NULL, NULL, &size); - if (!tty) - fatal_moan ("unable to open a ptty"); - } else { - /*HACK-- check that console=device does not occur in */ - /*/proc/cmdline */ - if (!oargs['d']) - fatal_moan ("no argument to -d"); - { - char kernel_cmdline[4096] = { 0 }; - char search_string[1024] = "console="; - char *ptr = oargs['d']; - int fd; + if (!oflags['k']) + { + pid = getpid (); - if (!strncmp ("/dev/", ptr, 5)) - ptr += 5; + oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); + oflags['k']++; + } - strcat (search_string, ptr); + server_socket = socket_listen (oargs['k']); - fd = open ("/proc/cmdline", O_RDONLY); - read (fd, kernel_cmdline, sizeof (kernel_cmdline)); - close (fd); + /*Tell our parent's parent what our pid is */ + if (csnok) + { + pid = getpid (); - kernel_cmdline[sizeof (kernel_cmdline) - 1] = 0; + write (csnok_pipe[1], &pid, sizeof (pid)); + close (csnok_pipe[1]); + } - if (strstr (kernel_cmdline, search_string)) - fatal_moan ("/proc/cmdline contains %s", search_string); - } + if (!server_socket) + fatal_moan ("failed to create socket %s for listening", oargs['k']); - tty = - serial_open (oargs['d'], - oflags['K'] ? SERIAL_LOCK_ACTIVE : SERIAL_LOCK_PASSIVE); - if (!tty) - fatal_moan ("unable to open serial port %s", oargs['d']); } - if (oflags['b']) { - int baud = safe_atoi (oargs['b']); - - if (baud < 0) - fatal_moan ("Unable to parse baudrate %s", oargs['b']); - - tty_set_baud (tty, baud); - + if (oflags['s'] || oflags['t']) + { + if (oflags['P']) + { + FILE *fp; + pid_file = oargs['P']; + fp = fopen (pid_file, "w"); + if (fp) + { + fprintf (fp, "%d", getpid ()); + fclose (fp); + } + } + + if (oflags['L']) + { + log = file_log_new (oargs['L'], oflags['R']); + if (!log) + fatal_moan ("unable to access log file %s", oargs['L']); + } + + if (oflags['p']) + { + tty = ptty_open (NULL, NULL, &size); + if (!tty) + fatal_moan ("unable to open a ptty"); + } + else + { + /*HACK-- check that console=device does not occur in */ + /*/proc/cmdline */ + if (!oargs['d']) + fatal_moan ("no argument to -d"); + + { + char kernel_cmdline[4096] = { 0 }; + char search_string[1024] = "console="; + char *ptr = oargs['d']; + int fd; + + if (!strncmp ("/dev/", ptr, 5)) + ptr += 5; + + strcat (search_string, ptr); + + fd = open ("/proc/cmdline", O_RDONLY); + read (fd, kernel_cmdline, sizeof (kernel_cmdline)); + close (fd); + + kernel_cmdline[sizeof (kernel_cmdline) - 1] = 0; + + if (strstr (kernel_cmdline, search_string)) + fatal_moan ("/proc/cmdline contains %s", search_string); + } + + tty = + serial_open (oargs['d'], + oflags['K'] ? SERIAL_LOCK_ACTIVE : + SERIAL_LOCK_PASSIVE); + if (!tty) + fatal_moan ("unable to open serial port %s", oargs['d']); + } + + if (oflags['b']) + { + int baud = safe_atoi (oargs['b']); + + if (baud < 0) + fatal_moan ("Unable to parse baudrate %s", oargs['b']); + + tty_set_baud (tty, baud); + + } + + tty_set_flow (tty, oflags['f'] ? 1 : 0); } - tty_set_flow (tty, oflags['f'] ? 1 : 0); - } - - if (oflags['r']) { - char *id = oargs['r']; + if (oflags['r']) + { + char *id = oargs['r']; - if (!id) - fatal_moan ("-r requires an argument"); + if (!id) + fatal_moan ("-r requires an argument"); - if (safe_atoi (id) > 0) { - client_socket = find_socket ("%s%d", hostname, safe_atoi (id)); - } else { - client_socket = find_socket ("%s", id); - } + if (safe_atoi (id) > 0) + { + client_socket = find_socket ("%s%d", hostname, safe_atoi (id)); + } + else + { + client_socket = find_socket ("%s", id); + } - if (!client_socket) - fatal_moan ("failed to find socket %s", oargs['r']); + if (!client_socket) + fatal_moan ("failed to find socket %s", oargs['r']); - } else if (oflags['c']) { - client_socket = socket_connect (oargs['k']); - - if (!client_socket) - fatal_moan ("failed to connect to socket %s", oargs['k']); + } + else if (oflags['c']) + { + client_socket = socket_connect (oargs['k']); - } + if (!client_socket) + fatal_moan ("failed to connect to socket %s", oargs['k']); + } - if (oflags['c'] || oflags['t']) { - if (oflags['H']) { - ansi = ansi_new_html (stdout); - } else { - terminal_register_handlers (); - ansi = - ansi_new_from_terminal (terminal_open (0, 1), oflags['u'] ? 0 : 1); - ansi->reset (ansi, NULL); + if (oflags['c'] || oflags['t']) + { + + if (oflags['H']) + { + ansi = ansi_new_html (stdout); + } + else + { + terminal_register_handlers (); + ansi = + ansi_new_from_terminal (terminal_open (0, 1), + oflags['u'] ? 0 : 1); + ansi->reset (ansi, NULL); + } } - } mainloop (tty, server_socket, client_socket, ansi, log, history, &size); - if (ansi) { - ansi->close (ansi); - terminal_atexit (); - } + if (ansi) + { + ansi->close (ansi); + terminal_atexit (); + } if (tty) tty->close (tty); @@ -754,7 +829,7 @@ main (int argc, char *argv[]) socket_free (client_socket); if (pid_file) - unlink(pid_file); + unlink (pid_file); if (!oflags['H']) printf ("you have now exited sympathy\n"); diff --git a/apps/usage.c b/apps/usage.c index 1aed8f0..bd15912 100644 --- a/apps/usage.c +++ b/apps/usage.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.19 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.18 2008/03/03 06:04:18 james * *** empty log message *** * @@ -125,7 +128,7 @@ usage (void) " -n nlines the number of lines of history to store in the\n" " server, that are replayed on connexion\n" " -P pidfile write the pid of the server/terminal process to pidfile\n" - " -R rotate logile specified with -L option\n" + " -R rotate logile specified with -L option\n" " -u don't emit utf-8 try to use ISO-2202 to the local terminal\n" " -w W[xH] start session with a screen of size W by H. 0pos.x = ANSI_INVAL; - if (a->pos.x != ANSI_INVAL) { - - if ((!dx) && (!dy)) - return; + if (a->pos.x != ANSI_INVAL) + { - if (!dy) { - if (dx == 1) { - a->terminal->xmit (a->terminal, "\033[C", 3); - } else if (dx == -1) { - a->terminal->xmit (a->terminal, "\033[D", 3); - } else { - n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1); - a->terminal->xmit (a->terminal, buf, n); - } - } else if (!dx) { - if (dy == -1) { - a->terminal->xmit (a->terminal, "\033[A", 3); - } else if (dy == 1) { - a->terminal->xmit (a->terminal, "\033[B", 3); - } else if (dy < 0) { - n = snprintf (buf, sizeof (buf), "\033[%dA", -dy); - a->terminal->xmit (a->terminal, buf, n); - } else { - n = snprintf (buf, sizeof (buf), "\033[%dB", dy); - a->terminal->xmit (a->terminal, buf, n); - } - } else if (!p.x) { - if (dy == 1) { - a->terminal->xmit (a->terminal, "\033[E", 3); - } else if (dy == -1) { - a->terminal->xmit (a->terminal, "\033[F", 3); - } else if (dy > 0) { - n = snprintf (buf, sizeof (buf), "\033[%dE", dy); - a->terminal->xmit (a->terminal, buf, n); - } else { - n = snprintf (buf, sizeof (buf), "\033[%dF", -dy); - a->terminal->xmit (a->terminal, buf, n); - } - } else { + if ((!dx) && (!dy)) + return; + + if (!dy) + { + if (dx == 1) + { + a->terminal->xmit (a->terminal, "\033[C", 3); + } + else if (dx == -1) + { + a->terminal->xmit (a->terminal, "\033[D", 3); + } + else + { + n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1); + a->terminal->xmit (a->terminal, buf, n); + } + } + else if (!dx) + { + if (dy == -1) + { + a->terminal->xmit (a->terminal, "\033[A", 3); + } + else if (dy == 1) + { + a->terminal->xmit (a->terminal, "\033[B", 3); + } + else if (dy < 0) + { + n = snprintf (buf, sizeof (buf), "\033[%dA", -dy); + a->terminal->xmit (a->terminal, buf, n); + } + else + { + n = snprintf (buf, sizeof (buf), "\033[%dB", dy); + a->terminal->xmit (a->terminal, buf, n); + } + } + else if (!p.x) + { + if (dy == 1) + { + a->terminal->xmit (a->terminal, "\033[E", 3); + } + else if (dy == -1) + { + a->terminal->xmit (a->terminal, "\033[F", 3); + } + else if (dy > 0) + { + n = snprintf (buf, sizeof (buf), "\033[%dE", dy); + a->terminal->xmit (a->terminal, buf, n); + } + else + { + n = snprintf (buf, sizeof (buf), "\033[%dF", -dy); + a->terminal->xmit (a->terminal, buf, n); + } + } + else + { + n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); + a->terminal->xmit (a->terminal, buf, n); + } + } + else + { n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); a->terminal->xmit (a->terminal, buf, n); } - } else { - n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); - a->terminal->xmit (a->terminal, buf, n); - } a->pos = p; } @@ -204,11 +236,14 @@ ansi_showhide_cursor (ANSI * a, int hide) if (a->hide_cursor == hide) return; - if (hide) { - a->terminal->xmit (a->terminal, "\033[?25l", 6); - } else { - a->terminal->xmit (a->terminal, "\033[?25h", 6); - } + if (hide) + { + a->terminal->xmit (a->terminal, "\033[?25l", 6); + } + else + { + a->terminal->xmit (a->terminal, "\033[?25h", 6); + } a->hide_cursor = hide; } @@ -230,30 +265,37 @@ 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 (fg & CRT_COLOR_INTENSITY) { - fg += 90; - } else { - fg += 30; - } - - if (bg & CRT_COLOR_INTENSITY) { - bg += 100; - } else { - bg += 40; - } - - i = sprintf (buf, "\033[%d;%dm", fg, bg); + if ((a->color == ANSI_INVAL) || (color != a->color)) + { + fg = CRT_COLOR_FG (color); + bg = CRT_COLOR_BG (color); + + if (fg & CRT_COLOR_INTENSITY) + { + fg += 90; + } + else + { + fg += 30; + } + + if (bg & CRT_COLOR_INTENSITY) + { + bg += 100; + } + else + { + bg += 40; + } + + 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; - } + a->terminal->xmit (a->terminal, buf, i); + a->color = color; + } } static void @@ -269,34 +311,47 @@ ansi_set_attr (ANSI * a, int attr) a->attr = attr; #if 0 - if (attr == CRT_ATTR_NORMAL) { - ansi_force_attr_normal (a); - return; - } + if (attr == CRT_ATTR_NORMAL) + { + ansi_force_attr_normal (a); + return; + } #endif - if (dif & CRT_ATTR_UNDERLINE) { - if (attr & CRT_ATTR_UNDERLINE) { - a->terminal->xmit (a->terminal, "\033[4m", 4); - } else { - a->terminal->xmit (a->terminal, "\033[24m", 5); - } - } - if (dif & CRT_ATTR_REVERSE) { - if (attr & CRT_ATTR_REVERSE) { - a->terminal->xmit (a->terminal, "\033[7m", 4); - } else { - a->terminal->xmit (a->terminal, "\033[27m", 5); - } - } - if (dif & CRT_ATTR_BOLD) { - if (attr & CRT_ATTR_BOLD) { - a->terminal->xmit (a->terminal, "\033[1m", 4); - } else { - a->terminal->xmit (a->terminal, "\033[21m", 5); - a->terminal->xmit (a->terminal, "\033[22m", 5); - } - } + if (dif & CRT_ATTR_UNDERLINE) + { + if (attr & CRT_ATTR_UNDERLINE) + { + a->terminal->xmit (a->terminal, "\033[4m", 4); + } + else + { + a->terminal->xmit (a->terminal, "\033[24m", 5); + } + } + if (dif & CRT_ATTR_REVERSE) + { + if (attr & CRT_ATTR_REVERSE) + { + a->terminal->xmit (a->terminal, "\033[7m", 4); + } + else + { + a->terminal->xmit (a->terminal, "\033[27m", 5); + } + } + if (dif & CRT_ATTR_BOLD) + { + if (attr & CRT_ATTR_BOLD) + { + a->terminal->xmit (a->terminal, "\033[1m", 4); + } + else + { + a->terminal->xmit (a->terminal, "\033[21m", 5); + a->terminal->xmit (a->terminal, "\033[22m", 5); + } + } } @@ -306,33 +361,37 @@ ascii_emit (TTY * t, uint32_t ch) int i; /*Some quick obvious subsititons for quotation marks*/ - switch (ch) { - case 0x2018: - ch = '`'; - break; - case 0x2019: - ch = '\''; - break; - case 0x201c: - case 0x201d: - ch = '"'; - break; - } + switch (ch) + { + case 0x2018: + ch = '`'; + break; + case 0x2019: + ch = '\''; + break; + case 0x201c: + case 0x201d: + ch = '"'; + break; + } /*Short cut the easy stuff*/ - if (ch < 0x7f) { - uint8_t c = ch; - t->xmit (t, &c, 1); - return; - } - - for (i = 0; i < VT102_CHARSET_SIZE; ++i) { - if (vt102_charset_gl[i] == ch) { - uint8_t c[3] = { 016, i, 017 }; - t->xmit (t, &c, 3); + if (ch < 0x7f) + { + uint8_t c = ch; + t->xmit (t, &c, 1); return; } - } + + for (i = 0; i < VT102_CHARSET_SIZE; ++i) + { + if (vt102_charset_gl[i] == ch) + { + uint8_t c[3] = { 016, i, 017 }; + t->xmit (t, &c, 3); + return; + } + } t->xmit (t, "?", 1); @@ -426,11 +485,12 @@ ansi_spot_scroll_up (ANSI * a, CRT * c) 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; - } + 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; @@ -438,10 +498,11 @@ ansi_spot_scroll_up (ANSI * a, CRT * c) 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; - } + while (n--) + { + memcpy (&a->crt.screen[p], &a->crt.screen[p + CRT_COLS], l); + p += CRT_COLS; + } c->sh.dir = 0; //FIXME: horrid hack @@ -451,12 +512,13 @@ static void ansi_spot_scroll (ANSI * a, CRT * c) { - switch (c->sh.dir) { - case -1: + switch (c->sh.dir) + { + case -1: /*we only care about up for the moment */ - ansi_spot_scroll_up (a, c); - break; - } + ansi_spot_scroll_up (a, c); + break; + } return; } @@ -470,21 +532,23 @@ ansi_draw_line (ANSI * a, CRT_CA * cap, int y) CRT_Pos p = { 0, y }; CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)]; - for (p.x = 0; p.x < a->crt.size.x; ++p.x) { - if (p.x >= a->size.x) - continue; + for (p.x = 0; p.x < a->crt.size.x; ++p.x) + { + if (p.x >= a->size.x) + continue; - if (crt_ca_cmp (*acap, *cap)) { - ansi_showhide_cursor (a, 1); - *acap = *cap; + if (crt_ca_cmp (*acap, *cap)) + { + ansi_showhide_cursor (a, 1); + *acap = *cap; - ansi_move (a, p); - ansi_render (a, *acap); - } + ansi_move (a, p); + ansi_render (a, *acap); + } - acap++; - cap++; - } + acap++; + cap++; + } } static void @@ -492,38 +556,42 @@ ansi_resize_check (ANSI * a, CRT_Pos * size) { if ((size && crt_pos_cmp (a->crt.size, *size)) - || crt_pos_cmp (a->terminal->size, a->size)) { + || crt_pos_cmp (a->terminal->size, a->size)) + { - terminal_getsize (a->terminal); + terminal_getsize (a->terminal); - a->size = a->terminal->size; + a->size = a->terminal->size; - a->pos.x = ANSI_INVAL; - a->hide_cursor = ANSI_INVAL; + a->pos.x = ANSI_INVAL; + a->hide_cursor = ANSI_INVAL; - crt_reset (&a->crt); + crt_reset (&a->crt); - if (size) - a->crt.size = *size; + if (size) + a->crt.size = *size; // FIXME: -- echos back crap? // a->terminal->xmit (a->terminal, "\033[c", 3); // 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->utf8) { - a->terminal->xmit (a->terminal, "\033%G", 3); - } else { - a->terminal->xmit (a->terminal, "\033(B", 3); - a->terminal->xmit (a->terminal, "\033)0", 3); - a->terminal->xmit (a->terminal, "\017", 1); - } + 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->utf8) + { + a->terminal->xmit (a->terminal, "\033%G", 3); + } + 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 they haven't then ansi_draw will patch it up*/ @@ -553,52 +621,55 @@ ansi_history (ANSI * a, History * h) 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; + while (a->history_ptr != h->wptr) + { - /*If so write the line ot the top of the screen */ - ansi_draw_line (a, e->line, 0); + History_ent *e = &h->lines[a->history_ptr]; + HISTORY_INC (h, a->history_ptr); - /*Roll guess_scroll lines up putting the top line into the xterm's history */ + if (!e->valid) + continue; + /*If so write the line ot the top of the screen */ + ansi_draw_line (a, e->line, 0); - /*Make extra lines a predictable colour */ - ansi_set_color (a, CRT_COLOR_NORMAL); - 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); - a->pos.x = ANSI_INVAL; + /*Roll guess_scroll lines up putting the top line into the xterm's history */ - /*now do the same in our image of the screen */ - { - CRT_Pos s = { 0 } - , e = { - 0}; + /*Make extra lines a predictable colour */ + ansi_set_color (a, CRT_COLOR_NORMAL); - /*scroll lines up */ - for (s.y++; s.y < guess_scroll; s.y++, e.y++) { - memcpy (&a->crt.screen[CRT_ADDR_POS (&e)], - &a->crt.screen[CRT_ADDR_POS (&s)], - sizeof (CRT_CA) * a->crt.size.x); + 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); + 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 < guess_scroll; s.y++, e.y++) + { + memcpy (&a->crt.screen[CRT_ADDR_POS (&e)], + &a->crt.screen[CRT_ADDR_POS (&s)], + sizeof (CRT_CA) * a->crt.size.x); + } + + /* erase new line */ + s.y = e.y; + e.x = CRT_COLS - 1; + crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL); } - /* erase new line */ - s.y = e.y; - e.x = CRT_COLS - 1; - crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL); } - - } /*reset margins*/ a->terminal->xmit (a->terminal, "\033[r", 3); a->pos.x = ANSI_INVAL; @@ -618,39 +689,42 @@ ansi_draw (ANSI * a, CRT * c) ansi_resize_check (a, &c->size); - for (p.y = 0; p.y < a->crt.size.y; ++p.y) { - if (p.y >= a->size.y) - continue; + for (p.y = 0; p.y < a->crt.size.y; ++p.y) + { + if (p.y >= a->size.y) + continue; - ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y); + ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y); - } + } - if ((c->size.x > a->size.x) || (c->size.y > a->size.y)) { - char msg[1024]; // = "Window is too small"; - int i; - p.x = 0; - p.y = 0; + if ((c->size.x > a->size.x) || (c->size.y > a->size.y)) + { + 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, c->size.x, c->size.y); + i = + 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); + 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, i); - a->pos.x = ANSI_INVAL; - } + 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; - } + if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y)) + { + ansi_showhide_cursor (a, 1); + return; + } a->crt.pos = c->pos; ansi_move (a, a->crt.pos); @@ -684,17 +758,25 @@ ansi_key (ANSI * a, Context * c, int key) cmd_show_status (c->d, c); - if (c->d->active) { - if (key == CMD_CANCEL_KEY) { - return cmd_deactivate (c->d, c); - } else if (key == CMD_KEY) { - cmd_deactivate (c->d, c); - } else { - return cmd_key (c->d, c, a, key); + if (c->d->active) + { + if (key == CMD_CANCEL_KEY) + { + return cmd_deactivate (c->d, c); + } + else if (key == CMD_KEY) + { + cmd_deactivate (c->d, c); + } + else + { + return cmd_key (c->d, c, a, key); + } + } + else if (key == CMD_KEY) + { + return cmd_activate (c->d, c); } - } else if (key == CMD_KEY) { - return cmd_activate (c->d, c); - } return c->k->key (c->k, c, key); } @@ -706,9 +788,10 @@ ansi_flush_escape (ANSI * a, Context * c) ANSI_Parser *p = &a->parser; int i; - for (i = 0; i < p->escape_ptr; ++i) { - ansi_key (a, c, p->escape_buf[i]); - } + for (i = 0; i < p->escape_ptr; ++i) + { + ansi_key (a, c, p->escape_buf[i]); + } p->escape_ptr = 0; p->in_escape = 0; @@ -718,19 +801,25 @@ static void ansi_parse_deckey (ANSI * a, Context * c) { ANSI_Parser *p = &a->parser; - if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O')) { - ansi_flush_escape (a, c); - return; - } + if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O')) + { + ansi_flush_escape (a, c); + return; + } - if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z')) { - ansi_key (a, c, KEY_UP + (p->escape_buf[2] - 'A')); - } else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z')) { - ansi_key (a, c, KEY_154 + (p->escape_buf[2] - 'a')); - } else { - ansi_flush_escape (a, c); - return; - } + if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z')) + { + ansi_key (a, c, KEY_UP + (p->escape_buf[2] - 'A')); + } + else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z')) + { + ansi_key (a, c, KEY_154 + (p->escape_buf[2] - 'a')); + } + else + { + ansi_flush_escape (a, c); + return; + } p->in_escape = 0; p->escape_ptr = 0; } @@ -740,16 +829,20 @@ ansi_parse_ansikey (ANSI * a, Context * c) { ANSI_Parser *p = &a->parser; - if ((p->escape_buf[1] != '[') || (p->escape_buf[3] != '~')) { - ansi_flush_escape (a, c); - return; - } - if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9')) { - ansi_key (a, c, KEY_180 + (p->escape_buf[2] - '0')); - } else { - ansi_flush_escape (a, c); - return; - } + if ((p->escape_buf[1] != '[') || (p->escape_buf[3] != '~')) + { + ansi_flush_escape (a, c); + return; + } + if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9')) + { + ansi_key (a, c, KEY_180 + (p->escape_buf[2] - '0')); + } + else + { + ansi_flush_escape (a, c); + return; + } p->in_escape = 0; p->escape_ptr = 0; @@ -761,44 +854,48 @@ static void ansi_parse_escape (ANSI * a, Context * c) { ANSI_Parser *p = &a->parser; - switch (p->escape_ptr) { - case 0: - case 1: - return; - case 2: - switch (p->escape_buf[1]) { - case '[': - case 'O': - break; - default: - ansi_flush_escape (a, c); - } - break; - case 3: - switch (p->escape_buf[1]) { - case 'O': - ansi_parse_deckey (a, c); + switch (p->escape_ptr) + { + case 0: + case 1: + return; + case 2: + switch (p->escape_buf[1]) + { + case '[': + case 'O': + break; + default: + ansi_flush_escape (a, c); + } break; - case '[': - if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z')) - ansi_parse_deckey (a, c); + case 3: + switch (p->escape_buf[1]) + { + case 'O': + ansi_parse_deckey (a, c); + break; + case '[': + if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z')) + ansi_parse_deckey (a, c); + break; + default: + ansi_flush_escape (a, c); + } break; - default: - ansi_flush_escape (a, c); - } - break; - case 4: - switch (p->escape_buf[1]) { - case '[': - ansi_parse_ansikey (a, c); + case 4: + switch (p->escape_buf[1]) + { + case '[': + ansi_parse_ansikey (a, c); + break; + default: + ansi_flush_escape (a, c); + } break; - default: + case 5: ansi_flush_escape (a, c); } - break; - case 5: - ansi_flush_escape (a, c); - } } @@ -835,21 +932,25 @@ ansi_parse_char (ANSI * a, Context * c, int ch) /*See if it's time to flush the escape*/ ansi_check_escape (a, c); - if (ch == 033) { - if (p->in_escape) - ansi_flush_escape (a, c); + if (ch == 033) + { + if (p->in_escape) + ansi_flush_escape (a, c); - p->in_escape++; - p->escape_ptr = 0; - gettimeofday (&p->last_escape, NULL); - } + p->in_escape++; + p->escape_ptr = 0; + gettimeofday (&p->last_escape, NULL); + } - if (p->in_escape) { - p->escape_buf[p->escape_ptr++] = ch; - ansi_parse_escape (a, c); - } else { - ansi_key (a, c, ch); - } + if (p->in_escape) + { + p->escape_buf[p->escape_ptr++] = ch; + ansi_parse_escape (a, c); + } + else + { + ansi_key (a, c, ch); + } } @@ -882,13 +983,14 @@ ansi_dispatch (ANSI * a, Context * c) #endif #if 0 - if (*buf == 2) { + if (*buf == 2) + { #if 0 - a->history_ptr = c->h->wptr; - HISTORY_INC (c->h, a->history_ptr); + a->history_ptr = c->h->wptr; + HISTORY_INC (c->h, a->history_ptr); #endif - return -1; - } + return -1; + } #endif diff --git a/src/ansi.h b/src/ansi.h index 00d2edf..2be0ab7 100644 --- a/src/ansi.h +++ b/src/ansi.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.15 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.14 2008/03/02 10:37:56 james * *** empty log message *** * @@ -64,7 +67,8 @@ #define ANSI_ESCAPE_BUF_LEN 10 #define ANSI_ESCAPE_TIMEOUT 100000 /*in ms */ -typedef struct { +typedef struct +{ int in_escape; struct timeval last_escape; char escape_buf[ANSI_ESCAPE_BUF_LEN]; @@ -74,7 +78,8 @@ typedef struct { struct CRT_struct; struct Context_struct; -typedef struct ANSI_struct { +typedef struct ANSI_struct +{ ANSI_Parser parser; TTY *terminal; diff --git a/src/cmd.c b/src/cmd.c index aa1c272..2707332 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.11 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.10 2008/03/02 10:50:32 staffcvs * *** empty log message *** * @@ -66,11 +69,13 @@ cmd_parse (Cmd * c, Context * ctx, ANSI * a, char *buf) ctx->k->hangup (ctx->k, ctx); else if (!strcmp (buf, "reset")) ctx->k->reset (ctx->k, ctx); - else if (!strcmp (buf, "expand")) { - int w = a->terminal->size.x; - int h = a->terminal->size.y - 1; - ctx->k->set_size (ctx->k, ctx, w, h); - } else if (!strncmp (buf, "width", 5)) + else if (!strcmp (buf, "expand")) + { + int w = a->terminal->size.x; + int h = a->terminal->size.y - 1; + ctx->k->set_size (ctx->k, ctx, w, h); + } + else if (!strncmp (buf, "width", 5)) ctx->k->set_size (ctx->k, ctx, atoi (buf + 5), 0); else if (!strncmp (buf, "height", 6)) ctx->k->set_size (ctx->k, ctx, 0, atoi (buf + 6)); @@ -101,35 +106,42 @@ int cmd_key (Cmd * c, Context * ctx, ANSI * a, int key) { - if (c->error) { - c->error = 0; - c->active = 0; - cmd_show_status (c, ctx); - return 0; - } - - if (key == 13) { - if (cmd_parse (c, ctx, a, c->buf + 1)) { - c->error++; - } else { + if (c->error) + { + c->error = 0; c->active = 0; + cmd_show_status (c, ctx); + return 0; } - cmd_show_status (c, ctx); - return 0; - } - if (((key == 8) || (key == 127)) && (c->ptr > 1)) { - c->ptr--; - c->buf[c->ptr] = 0; - } + if (key == 13) + { + if (cmd_parse (c, ctx, a, c->buf + 1)) + { + c->error++; + } + else + { + c->active = 0; + } + cmd_show_status (c, ctx); + return 0; + } + + if (((key == 8) || (key == 127)) && (c->ptr > 1)) + { + c->ptr--; + c->buf[c->ptr] = 0; + } - if ((key >= 32) && (key < 127)) { + if ((key >= 32) && (key < 127)) + { - c->buf[c->ptr] = key; - c->ptr++; - c->buf[c->ptr] = 0; + c->buf[c->ptr] = key; + c->ptr++; + c->buf[c->ptr] = 0; - } + } cmd_show_status (c, ctx); diff --git a/src/cmd.h b/src/cmd.h index 4b3dfa1..2a199e0 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.6 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.5 2008/03/02 12:30:54 staffcvs * *** empty log message *** * @@ -33,9 +36,10 @@ #define __CMD_H__ #define CMD_KEY 2 /*CTRL B */ -#define CMD_CANCEL_KEY 3 /*CTRL C */ +#define CMD_CANCEL_KEY 3 /*CTRL C */ -typedef struct { +typedef struct +{ int active; int error; int disconnect; diff --git a/src/context.h b/src/context.h index 0ca8f20..33e9f2c 100644 --- a/src/context.h +++ b/src/context.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.10 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.9 2008/03/02 10:37:56 james * *** empty log message *** * @@ -44,7 +47,8 @@ #ifndef __CONTEXT_H__ #define __CONTEXT_H__ -typedef struct Context_struct { +typedef struct Context_struct +{ VT102 *v; TTY *t; TTY_Parser *tp; diff --git a/src/crt.c b/src/crt.c index aacdc8b..8caca0c 100644 --- a/src/crt.c +++ b/src/crt.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.17 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.16 2008/03/02 10:37:56 james * *** empty log message *** * @@ -68,14 +71,16 @@ crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color) CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)]; CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)]; - while (ps <= pe) { - ps->chr = ' '; - if (ea) { - ps->attr = CRT_ATTR_NORMAL; - ps->color = color; + while (ps <= pe) + { + ps->chr = ' '; + if (ea) + { + ps->attr = CRT_ATTR_NORMAL; + ps->color = color; + } + ps++; } - ps++; - } } @@ -117,10 +122,11 @@ crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color) p = CRT_ADDR_POS (&s); - while (n--) { - memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l); - p += CRT_COLS; - } + while (n--) + { + memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l); + p += CRT_COLS; + } s.y = e.y; crt_erase (c, s, e, ea, color); @@ -151,10 +157,11 @@ crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color) p = CRT_ADDR_POS (&e); - while (n--) { - p -= CRT_COLS; - memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l); - } + while (n--) + { + p -= CRT_COLS; + memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l); + } e.y = s.y; crt_erase (c, s, e, ea, color); diff --git a/src/crt.h b/src/crt.h index 683dc2b..9ba699d 100644 --- a/src/crt.h +++ b/src/crt.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.16 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.15 2008/03/02 10:37:56 james * *** empty log message *** * @@ -102,25 +105,29 @@ #define CRT_COLOR_NORMAL CRT_MAKE_COLOR(CRT_FGCOLOR_NORMAL,CRT_BGCOLOR_NORMAL) -typedef struct __attribute__ ((packed)) { +typedef struct __attribute__ ((packed)) +{ uint32_t chr; uint8_t attr; uint8_t color; } CRT_CA; -typedef struct { +typedef struct +{ int x; int y; } CRT_Pos; -typedef struct { +typedef struct +{ CRT_Pos s; CRT_Pos e; int dir; } CRT_ScrollHint; -typedef struct CRT_struct { +typedef struct CRT_struct +{ CRT_CA screen[CRT_CELS]; CRT_Pos pos; int hide_cursor; diff --git a/src/history.c b/src/history.c index ed613a4..bfb28dc 100644 --- a/src/history.c +++ b/src/history.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.5 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.4 2008/03/02 10:37:56 james * *** empty log message *** * @@ -69,10 +72,11 @@ history_add (History * h, CRT_CA * c) #if 0 { int i = CRT_COLS; - while (i--) { - fputc (c->chr, stderr); - c++; - } + while (i--) + { + fputc (c->chr, stderr); + c++; + } fputc ('\n', stderr); } #endif diff --git a/src/history.h b/src/history.h index 010beb1..009b439 100644 --- a/src/history.h +++ b/src/history.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.5 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.4 2008/03/02 10:37:56 james * *** empty log message *** * @@ -29,13 +32,15 @@ #ifndef __HISTORY_H__ #define __HISTORY_H__ -typedef struct { +typedef struct +{ int valid; time_t t; CRT_CA line[CRT_COLS]; } History_ent; -typedef struct { +typedef struct +{ History_ent *lines; int nlines; int wptr; diff --git a/src/html.c b/src/html.c index 9e22560..db7e164 100644 --- a/src/html.c +++ b/src/html.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.11 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.10 2008/03/02 10:37:56 james * *** empty log message *** * @@ -71,29 +74,35 @@ static int colormap[] = { static void html_entity (FILE * f, int c) { - switch (c) { - case 32: - fprintf (f, " "); - break; - case 38: - fprintf (f, "&"); - break; - case 60: - fprintf (f, "<"); - break; - case 62: - fprintf (f, ">"); - break; - default: - - if ((c >= 32) && (c < 127)) { - fputc (c, f); - } else if (c > 127) { - fprintf (f, "&#x%04x;", c); - } else { - fputc (' ', f); + switch (c) + { + case 32: + fprintf (f, " "); + break; + case 38: + fprintf (f, "&"); + break; + case 60: + fprintf (f, "<"); + break; + case 62: + fprintf (f, ">"); + break; + default: + + if ((c >= 32) && (c < 127)) + { + fputc (c, f); + } + else if (c > 127) + { + fprintf (f, "&#x%04x;", c); + } + else + { + fputc (' ', f); + } } - } } static void @@ -101,15 +110,18 @@ html_render (FILE * f, CRT_CA c) { int fg, bg; - if (c.attr & CRT_ATTR_REVERSE) { - fg = CRT_COLOR_BG (c.color); - bg = CRT_COLOR_FG (c.color); - } else { - fg = CRT_COLOR_FG (c.color); - bg = CRT_COLOR_BG (c.color); - if (c.attr & CRT_ATTR_BOLD) - fg |= CRT_COLOR_INTENSITY; - } + if (c.attr & CRT_ATTR_REVERSE) + { + fg = CRT_COLOR_BG (c.color); + bg = CRT_COLOR_FG (c.color); + } + else + { + fg = CRT_COLOR_FG (c.color); + bg = CRT_COLOR_BG (c.color); + if (c.attr & CRT_ATTR_BOLD) + fg |= CRT_COLOR_INTENSITY; + } #ifdef CSS fprintf (f, "", colormap[fg], colormap[bg]); @@ -130,9 +142,10 @@ html_render (FILE * f, CRT_CA c) fprintf (f, ""); if (c.attr & CRT_ATTR_UNDERLINE) fprintf (f, ""); - if (c.attr & CRT_ATTR_REVERSE) { - fprintf (f, ""); - } + if (c.attr & CRT_ATTR_REVERSE) + { + fprintf (f, ""); + } #ifdef CSS fprintf (f, ""); #else @@ -152,20 +165,22 @@ html_draw (FILE * f, CRT * c) #else fprintf (f, "\n"); #endif - for (p.y = 0; p.y < c->size.y; ++p.y) { - o = CRT_ADDR (p.y, 0); + for (p.y = 0; p.y < c->size.y; ++p.y) + { + o = CRT_ADDR (p.y, 0); #ifndef CSS - fprintf (f, ""); + fprintf (f, ""); #endif - for (p.x = 0; p.x < c->size.x; ++p.x, ++o) { - html_render (f, c->screen[o]); - } + for (p.x = 0; p.x < c->size.x; ++p.x, ++o) + { + html_render (f, c->screen[o]); + } #ifdef CSS - fprintf (f, "\n"); + fprintf (f, "\n"); #else - fprintf (f, "\n"); + fprintf (f, "\n"); #endif - } + } #ifdef CSS fprintf (f, "\n"); #else diff --git a/src/ipc.h b/src/ipc.h index 87dc7ed..bd97759 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.8 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.7 2008/03/02 10:37:56 james * *** empty log message *** * @@ -55,32 +58,37 @@ #define IPC_MSG_TYPE_SETSIZE 12 #define IPC_MSG_TYPE_RESET 13 -typedef struct { +typedef struct +{ int32_t size; int32_t type; uint8_t payload[0]; } IPC_Msg_hdr; -typedef struct { +typedef struct +{ int32_t size; int32_t type; } IPC_Msg_noop; -typedef struct { +typedef struct +{ int32_t size; int32_t type; char msg[0]; } IPC_Msg_debug; -typedef struct { +typedef struct +{ int32_t size; int32_t type; History_ent history; } IPC_Msg_history; -typedef struct { +typedef struct +{ int32_t size; int32_t type; int32_t len; @@ -88,13 +96,15 @@ typedef struct { } IPC_Msg_VT102; -typedef struct { +typedef struct +{ int32_t size; int32_t type; int32_t key; } IPC_Msg_key; -typedef struct { +typedef struct +{ int32_t size; int32_t type; int32_t len; @@ -102,60 +112,69 @@ typedef struct { } IPC_Msg_term; -typedef struct { +typedef struct +{ int32_t size; int32_t type; char status[0]; } IPC_Msg_status; -typedef struct { +typedef struct +{ int32_t size; int32_t type; int32_t baud; } IPC_Msg_setbaud; -typedef struct { +typedef struct +{ int32_t size; int32_t type; } IPC_Msg_sendbreak; -typedef struct { +typedef struct +{ int32_t size; int32_t type; int32_t flow; } IPC_Msg_setflow; -typedef struct { +typedef struct +{ int32_t size; int32_t type; int32_t ansi; } IPC_Msg_setansi; -typedef struct { +typedef struct +{ int32_t size; int32_t type; } IPC_Msg_hangup; -typedef struct { +typedef struct +{ int32_t size; int32_t type; CRT_Pos winsize; } IPC_Msg_setsize; -typedef struct { +typedef struct +{ int32_t size; int32_t type; } IPC_Msg_reset; -typedef union { +typedef union +{ IPC_Msg_hdr hdr; IPC_Msg_noop noop; IPC_Msg_debug debug; diff --git a/src/keydis.c b/src/keydis.c index 49cbe86..02d412f 100644 --- a/src/keydis.c +++ b/src/keydis.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.11 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.10 2008/03/02 10:37:56 james * *** empty log message *** * @@ -50,11 +53,13 @@ static char rcsid[] = "$Id$"; #define CMD_BUFLEN 128 -typedef struct { +typedef struct +{ KEYDIS_SIGNATURE; } KeyDis_VT102; -typedef struct { +typedef struct +{ KEYDIS_SIGNATURE; Socket *s; } KeyDis_IPC; diff --git a/src/keydis.h b/src/keydis.h index 826ffc8..66cc586 100644 --- a/src/keydis.h +++ b/src/keydis.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.8 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.7 2008/03/02 10:37:56 james * *** empty log message *** * @@ -57,7 +60,8 @@ struct Context_struct; -typedef struct KeyDis_struct { +typedef struct KeyDis_struct +{ KEYDIS_SIGNATURE; } KeyDis; diff --git a/src/lockfile.c b/src/lockfile.c index 646ba01..6b08ae0 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.12 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.11 2008/03/02 10:38:18 james * *** empty log message *** * @@ -129,10 +132,11 @@ void filelist_print (Filelist * fl, FILE * f) { Filelist_ent *fle; - if (!fl) { - fprintf (f, "(empty list)\n"); - return; - } + if (!fl) + { + fprintf (f, "(empty list)\n"); + return; + } for (fle = fl->head; fle; fle = fle->next) fprintf (f, "%s\n", fle->name); } @@ -147,14 +151,18 @@ chown_uucp (fd) static int uuid = -1, ugid; struct passwd *pw; - if (uuid < 0) { - if (pw = getpwnam ("uucp")) { - uuid = pw->pw_uid; - ugid = pw->pw_gid; - } else { - return -1; + if (uuid < 0) + { + if (pw = getpwnam ("uucp")) + { + uuid = pw->pw_uid; + ugid = pw->pw_gid; + } + else + { + return -1; + } } - } return fchown (fd, uuid, ugid); } @@ -181,25 +189,28 @@ lockfile_make (char *name) unlink (tmpfn); fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444); - if (fd < 0) { - unlink (tmpfn); - return -1; - } + if (fd < 0) + { + unlink (tmpfn); + return -1; + } write (fd, buf, i); fchmod (fd, 044); - if (chown_uucp (fd)) { - close (fd); - unlink (tmpfn); - return -1; - } + if (chown_uucp (fd)) + { + close (fd); + unlink (tmpfn); + return -1; + } close (fd); - if (link (tmpfn, name) < 0) { - unlink (tmpfn); - return -1; - } + if (link (tmpfn, name) < 0) + { + unlink (tmpfn); + return -1; + } unlink (tmpfn); return 0; @@ -218,27 +229,29 @@ lockfile_add_places (Filelist * fl, char *leaf) }; int i; - for (i = 0; i < (sizeof (lock_dirs) / sizeof (char *)); ++i) { - if (stat (lock_dirs[i], &stbuf)) - continue; - strcpy (buf, lock_dirs[i]); - strcat (buf, "/"); - strcat (buf, leaf); - filelist_add (fl, buf); - } + for (i = 0; i < (sizeof (lock_dirs) / sizeof (char *)); ++i) + { + if (stat (lock_dirs[i], &stbuf)) + continue; + strcpy (buf, lock_dirs[i]); + strcat (buf, "/"); + strcat (buf, leaf); + filelist_add (fl, buf); + } } static void do_tedious_mangling (Filelist * fl, char *buf, char *ptr, char inv, int lower) { - while (*ptr) { - if (lower && (*ptr >= 'A') && (*ptr <= 'Z')) - *ptr |= 32; - if (*ptr == '/') - *ptr = inv; - ptr++; - } + while (*ptr) + { + if (lower && (*ptr >= 'A') && (*ptr <= 'Z')) + *ptr |= 32; + if (*ptr == '/') + *ptr = inv; + ptr++; + } lockfile_add_places (fl, buf); } @@ -277,10 +290,11 @@ lockfile_add_name_from_path (Filelist * fl, char *file) ptr++; lockfile_regularize_and_add (fl, ptr); - if (!strncmp (ptr, "dev/", 4)) { - ptr += 4; - lockfile_regularize_and_add (fl, ptr); - } + if (!strncmp (ptr, "dev/", 4)) + { + ptr += 4; + lockfile_regularize_and_add (fl, ptr); + } } @@ -305,20 +319,21 @@ lockfile_check_dir_for_dev (Filelist * fl, char *dir, dev_t dev) if (!d) return; - while ((de = readdir (d))) { - strcpy (buf, dir); - strcat (buf, de->d_name); + while ((de = readdir (d))) + { + strcpy (buf, dir); + strcat (buf, de->d_name); - if (stat (buf, &ent_stat)) - continue; - if (!S_ISCHR (ent_stat.st_mode)) - continue; - if (ent_stat.st_rdev != dev) - continue; + if (stat (buf, &ent_stat)) + continue; + if (!S_ISCHR (ent_stat.st_mode)) + continue; + if (ent_stat.st_rdev != dev) + continue; - lockfile_add_name_from_path (fl, buf); + lockfile_add_name_from_path (fl, buf); - } + } closedir (d); } @@ -365,28 +380,31 @@ remove_stale_lock (char *path) apid[length] = 0; pid = 0; - if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) { - pid = *((int *) apid); + if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) + { + pid = *((int *) apid); #ifdef LOCK_ASCII - fprintf (stderr, - "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", - length, pid); + fprintf (stderr, + "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", + length, pid); #endif - } + } #ifdef LOCK_BINARY - else { - fprintf (stderr, - "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!", - length, pid); - } + else + { + fprintf (stderr, + "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!", + length, pid); + } #endif close (fd); - if ((kill (pid, 0) < 0) && (errno == ESRCH)) { - fprintf (stderr, "removing stale lock file %s\n", path); - unlink (path); - } + if ((kill (pid, 0) < 0) && (errno == ESRCH)) + { + fprintf (stderr, "removing stale lock file %s\n", path); + unlink (path); + } } @@ -396,11 +414,12 @@ lockfile_remove_stale (Filelist * fl) Filelist_ent *fle; struct stat buf; - for (fle = fl->head; fle; fle = fle->next) { - if (stat (fle->name, &buf)) - continue; - remove_stale_lock (fle->name); - } + for (fle = fl->head; fle; fle = fle->next) + { + if (stat (fle->name, &buf)) + continue; + remove_stale_lock (fle->name); + } } @@ -416,14 +435,16 @@ lockfile_lock (Filelist * fl) lockfile_remove_stale (fl); - for (fle = fl->head; fle; fle = fle->next) { - if (lockfile_make (fle->name)) { - fprintf (stderr, "Failed to get lockfile %s\n", fle->name); - filelist_free (ret); - return NULL; + for (fle = fl->head; fle; fle = fle->next) + { + if (lockfile_make (fle->name)) + { + fprintf (stderr, "Failed to get lockfile %s\n", fle->name); + filelist_free (ret); + return NULL; + } + filelist_add (ret, fle->name); } - filelist_add (ret, fle->name); - } return ret; } @@ -432,10 +453,11 @@ void lockfile_unlock (Filelist * fl) { - while (fl->head) { - unlink (fl->head->name); - filelist_remove (fl, fl->head); - } + while (fl->head) + { + unlink (fl->head->name); + filelist_remove (fl, fl->head); + } } @@ -452,10 +474,11 @@ serial_lock_check (Serial_lock * l) if (l->mode == SERIAL_LOCK_ACTIVE) return 0; - for (fle = l->locks_to_check->head; fle; fle = fle->next) { - if (!stat (fle->name, &buf)) - locks_found++; - } + for (fle = l->locks_to_check->head; fle; fle = fle->next) + { + if (!stat (fle->name, &buf)) + locks_found++; + } if (!locks_found) return 0; @@ -463,10 +486,11 @@ serial_lock_check (Serial_lock * l) gettimeofday (&now, NULL); timersub (&now, &l->last_stale_purge, &dif); - if (dif.tv_sec > STALE_CHECK_INTERVAL) { - lockfile_remove_stale (l->locks_to_check); - l->last_stale_purge = now; - } + if (dif.tv_sec > STALE_CHECK_INTERVAL) + { + lockfile_remove_stale (l->locks_to_check); + l->last_stale_purge = now; + } return 1; } @@ -477,14 +501,16 @@ serial_lock_free (Serial_lock * l) if (!l) return; - if (l->locks_held) { - lockfile_unlock (l->locks_held); - filelist_free (l->locks_held); - } + if (l->locks_held) + { + lockfile_unlock (l->locks_held); + filelist_free (l->locks_held); + } - if (l->locks_to_check) { - filelist_free (l->locks_to_check); - } + if (l->locks_to_check) + { + filelist_free (l->locks_to_check); + } free (l); } @@ -510,10 +536,11 @@ serial_lock_new (char *dev, int mode) return l; l->locks_held = lockfile_lock (l->locks_to_check); - if (!l->locks_held) { - serial_lock_free (l); - return NULL; - } + if (!l->locks_held) + { + serial_lock_free (l); + return NULL; + } return l; } diff --git a/src/lockfile.h b/src/lockfile.h index 4364216..3736c08 100644 --- a/src/lockfile.h +++ b/src/lockfile.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.9 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.8 2008/03/02 10:37:56 james * *** empty log message *** * @@ -46,17 +49,20 @@ #define FILE_LIST_MAX_LEN 1024 -typedef struct Filelist_ent { +typedef struct Filelist_ent +{ char name[FILE_LIST_MAX_LEN]; struct Filelist_ent *next; } Filelist_ent; -typedef struct { +typedef struct +{ Filelist_ent *head; } Filelist; -typedef struct { +typedef struct +{ int mode; int i; struct timeval last_stale_purge; diff --git a/src/log.c b/src/log.c index dc15ed9..d8d9896 100644 --- a/src/log.c +++ b/src/log.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.8 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.7 2008/03/03 06:04:18 james * *** empty log message *** * @@ -35,7 +38,8 @@ static char rcsid[] = "$Id$"; #include "project.h" -typedef struct { +typedef struct +{ LOG_SIGNATURE; int do_close; int rotate; @@ -72,8 +76,8 @@ flog_log (Log * _l, char *buf) fputc ('\n', l->fp); fflush (l->fp); - if (l->rotate) - rotate_check(l->filename); + if (l->rotate) + rotate_check (l->filename); } @@ -86,25 +90,28 @@ flog_close (Log * _l) if (l->fp && l->do_close) fclose (l->fp); if (l->filename) - free(l->filename); + free (l->filename); free (l); } Log * -file_log_new (char *fn,int rotate) +file_log_new (char *fn, int rotate) { File_Log *l; FILE *f; int dc = 1; - if (fn && strcmp (fn, "-")) { - f = fopen (fn, "a+"); - if (!f) - return NULL; - } else { - f = stderr; - dc = 0; - } + if (fn && strcmp (fn, "-")) + { + f = fopen (fn, "a+"); + if (!f) + return NULL; + } + else + { + f = stderr; + dc = 0; + } l = malloc (sizeof (File_Log)); @@ -112,8 +119,8 @@ file_log_new (char *fn,int rotate) l->close = flog_close; l->fp = f; l->do_close = dc; - l->rotate=rotate; - l->filename=strdup(fn); + l->rotate = rotate; + l->filename = strdup (fn); fput_cp (f, 0xffef); @@ -132,32 +139,35 @@ log_f (Log * log, char *fmt, ...) if (!log) return; - if (!size) { - size = 128; - buf = malloc (size); - } + if (!size) + { + size = 128; + buf = malloc (size); + } if (!buf) return; - while (1) { - va_start (ap, fmt); - n = vsnprintf (buf, size, fmt, ap); - va_end (ap); + while (1) + { + va_start (ap, fmt); + n = vsnprintf (buf, size, fmt, ap); + va_end (ap); - if (n > -1 && n < size) { - log->log (log, buf); - return; - } + if (n > -1 && n < size) + { + log->log (log, buf); + return; + } - if (n > -1) /* glibc 2.1 */ - size = n + 1; - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ + if (n > -1) /* glibc 2.1 */ + size = n + 1; + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ - buf = realloc (buf, size); + buf = realloc (buf, size); - if (!buf) - return; - } + if (!buf) + return; + } } diff --git a/src/log.h b/src/log.h index 56b690f..ced5e5b 100644 --- a/src/log.h +++ b/src/log.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.4 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.3 2008/03/02 10:37:56 james * *** empty log message *** * @@ -30,7 +33,8 @@ void (*log)(struct Log_struct *,char *); \ void (*close)(struct Log_struct *) -typedef struct Log_struct { +typedef struct Log_struct +{ LOG_SIGNATURE; } Log; diff --git a/src/prototypes.h b/src/prototypes.h index eacb4f6..8f7fd79 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,181 +1,182 @@ /* 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 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); /* 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 void 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 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); /* 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 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); /* 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 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); /* vt102_charset.c */ extern uint32_t vt102_charset_c0[128]; extern uint32_t vt102_charset_us[128]; @@ -184,4 +185,4 @@ 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_check(char *file); +extern void rotate_check (char *file); diff --git a/src/ptty.c b/src/ptty.c index d97919c..cd3dbae 100644 --- a/src/ptty.c +++ b/src/ptty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.18 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.17 2008/03/02 10:37:56 james * *** empty log message *** * @@ -81,7 +84,8 @@ static char rcsid[] = "$Id$"; #include "project.h" -typedef struct { +typedef struct +{ TTY_SIGNATURE; int fd; pid_t child; @@ -108,18 +112,19 @@ ptty_read (TTY * _t, void *buf, int len) PTTY *t = (PTTY *) _t; int red, done = 0; - do { + do + { - red = wrap_read (t->fd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->fd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -133,18 +138,19 @@ ptty_write (TTY * _t, void *buf, int len) int writ, done = 0; PTTY *t = (PTTY *) _t; - do { + do + { - writ = wrap_write (t->fd, buf, len); - if (writ < 0) - return -1; - if (!writ) - sleep (1); + writ = wrap_write (t->fd, buf, len); + if (writ < 0) + return -1; + if (!writ) + sleep (1); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -169,20 +175,21 @@ ptty_open (char *path, char *argv[], CRT_Pos * size) child = forkpty (&fd, name, &ctermios, &winsize); - switch (child) { - case -1: /*boo hiss */ - return NULL; - case 0: /*waaah */ - setenv ("TERM", "xterm", 1); - if (!path) - path = "/bin/sh"; - - if (!argv) - argv = default_argv; - - execv (path, argv); - _exit (-1); - } + switch (child) + { + case -1: /*boo hiss */ + return NULL; + case 0: /*waaah */ + setenv ("TERM", "xterm", 1); + if (!path) + path = "/bin/sh"; + + if (!argv) + argv = default_argv; + + execv (path, argv); + _exit (-1); + } set_nonblocking (fd); diff --git a/src/ring.c b/src/ring.c index b5bcf76..9e04fd3 100644 --- a/src/ring.c +++ b/src/ring.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.6 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.5 2008/03/02 10:37:56 james * *** empty log message *** * @@ -34,14 +37,15 @@ ring_read (Ring * r, void *b, int n) { int red = 0; - while (n--) { + while (n--) + { - if (!ring_read_one (r, b)) - break; + if (!ring_read_one (r, b)) + break; - b++; - red++; - } + b++; + red++; + } return red; } @@ -51,14 +55,15 @@ ring_write (Ring * r, void *b, int n) { int writ = 0; - while (n--) { + while (n--) + { - if (!ring_write_one (r, b)) - break; + if (!ring_write_one (r, b)) + break; - b++; - writ++; - } + b++; + writ++; + } return writ; } diff --git a/src/ring.h b/src/ring.h index 05a0333..372fad3 100644 --- a/src/ring.h +++ b/src/ring.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.4 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.3 2008/03/02 10:37:56 james * *** empty log message *** * @@ -26,7 +29,8 @@ #ifndef __RING_H__ #define __RING_H__ -typedef struct { +typedef struct +{ uint8_t *ring; int wptr; int rptr; diff --git a/src/rotate.c b/src/rotate.c index fa8c17b..6291819 100644 --- a/src/rotate.c +++ b/src/rotate.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.1 2008/03/03 06:04:18 james * *** empty log message *** * @@ -21,6 +24,7 @@ static char rcsid[] = "$Id$"; -void rotate_check(char *file) +void +rotate_check (char *file) { } diff --git a/src/serial.c b/src/serial.c index 0284703..25748ac 100644 --- a/src/serial.c +++ b/src/serial.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.14 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.13 2008/03/02 10:37:56 james * *** empty log message *** * @@ -84,7 +87,8 @@ static char rcsid[] = "$Id$"; #include -typedef struct { +typedef struct +{ TTY_SIGNATURE; Serial_lock *lock; int fd; @@ -116,18 +120,19 @@ serial_read (TTY * _t, void *buf, int len) if (t->blocked) return 0; - do { + do + { - red = wrap_read (t->fd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->fd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -145,18 +150,19 @@ serial_write (TTY * _t, void *buf, int len) if (t->blocked) return 0; - do { + do + { - writ = wrap_write (t->fd, buf, len); - if (writ < 0) - return -1; - if (!writ) - sleep (1); + writ = wrap_write (t->fd, buf, len); + if (writ < 0) + return -1; + if (!writ) + sleep (1); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -184,16 +190,18 @@ serial_open (char *path, int lock_mode) set_nonblocking (fd); - if (tcgetattr (fd, &termios)) { - close (fd); - return NULL; - } + if (tcgetattr (fd, &termios)) + { + close (fd); + return NULL; + } default_termios (&termios); - if (tcsetattr (fd, TCSANOW, &termios)) { - close (fd); - return NULL; - } + if (tcsetattr (fd, TCSANOW, &termios)) + { + close (fd); + return NULL; + } t = (Serial *) malloc (sizeof (Serial)); diff --git a/src/slide.c b/src/slide.c index 3581f86..b04e430 100644 --- a/src/slide.c +++ b/src/slide.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.5 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.4 2008/03/02 10:37:56 james * *** empty log message *** * @@ -52,10 +55,11 @@ slide_consume (Slide * s, int n) memmove (s->slide, s->slide + n, s->nbytes); - if ((s->size > s->target_size) && (s->nbytes <= s->target_size)) { - s->size = s->target_size; - s->slide = realloc (s->slide, s->size); - } + if ((s->size > s->target_size) && (s->nbytes <= s->target_size)) + { + s->size = s->target_size; + s->slide = realloc (s->slide, s->size); + } } diff --git a/src/slide.h b/src/slide.h index 9705d5f..560aaea 100644 --- a/src/slide.h +++ b/src/slide.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.3 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.2 2008/03/02 10:37:56 james * *** empty log message *** * @@ -29,7 +32,8 @@ #ifndef __SLIDE_H__ #define __SLIDE_H__ -typedef struct { +typedef struct +{ uint8_t *slide; int nbytes; int target_size; diff --git a/src/symsocket.c b/src/symsocket.c index 6f33fe7..0978914 100644 --- a/src/symsocket.c +++ b/src/symsocket.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.8 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.7 2008/03/02 10:37:56 james * *** empty log message *** * @@ -83,10 +86,11 @@ socket_free (Socket * s) slide_free (s->read_buf); if (s->write_buf) slide_free (s->write_buf); - if (s->path_to_unlink) { - unlink (s->path_to_unlink); - free (s->path_to_unlink); - } + if (s->path_to_unlink) + { + unlink (s->path_to_unlink); + free (s->path_to_unlink); + } close (s->fd); free (s); } @@ -131,18 +135,20 @@ socket_listen (char *path) sun->sun_family = AF_UNIX; strcpy (sun->sun_path, path); - if (bind (fd, (struct sockaddr *) sun, SUN_LEN (sun)) < 0) { - free (sun); - close (fd); - return NULL; - } + if (bind (fd, (struct sockaddr *) sun, SUN_LEN (sun)) < 0) + { + free (sun); + close (fd); + return NULL; + } free (sun); - if (listen (fd, 5) < 0) { - close (fd); - return NULL; - } + if (listen (fd, 5) < 0) + { + close (fd); + return NULL; + } set_nonblocking (fd); @@ -210,11 +216,12 @@ socket_connect (char *path) sun->sun_family = AF_UNIX; strcpy (sun->sun_path, path); - if (connect (fd, (struct sockaddr *) sun, SUN_LEN (sun))) { - free (sun); - close (fd); - return NULL; - } + if (connect (fd, (struct sockaddr *) sun, SUN_LEN (sun))) + { + free (sun); + close (fd); + return NULL; + } free (sun); @@ -251,10 +258,11 @@ socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds) int n; /*Server socket */ - if (SOCKET_IS_LISTENER (s)) { - FD_SET (s->fd, rfds); - return; - } + if (SOCKET_IS_LISTENER (s)) + { + FD_SET (s->fd, rfds); + return; + } if (!SLIDE_EMPTY (s->write_buf)) FD_SET (s->fd, wfds); @@ -272,27 +280,29 @@ socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds) int error = 0; - if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds)) { - n = - (SLIDE_BYTES (s->write_buf) > - MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf); - n = wrap_send (s->fd, SLIDE_RPTR (s->write_buf), n); - if (n > 0) - slide_consume (s->write_buf, n); - if (n < 0) - error = -1; - } - - if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds)) { - n = - (SLIDE_SPACE (s->read_buf) > - MAX_TXN) ? MAX_TXN : SLIDE_SPACE (s->read_buf); - n = wrap_recv (s->fd, SLIDE_WPTR (s->read_buf), n); - if (n > 0) - slide_added (s->read_buf, n); - if (n < 0) - error = -1; - } + if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds)) + { + n = + (SLIDE_BYTES (s->write_buf) > + MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf); + n = wrap_send (s->fd, SLIDE_RPTR (s->write_buf), n); + if (n > 0) + slide_consume (s->write_buf, n); + if (n < 0) + error = -1; + } + + if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds)) + { + n = + (SLIDE_SPACE (s->read_buf) > + MAX_TXN) ? MAX_TXN : SLIDE_SPACE (s->read_buf); + n = wrap_recv (s->fd, SLIDE_WPTR (s->read_buf), n); + if (n > 0) + slide_added (s->read_buf, n); + if (n < 0) + error = -1; + } s->msg = ipc_check_for_message_in_slide (s->read_buf); diff --git a/src/symsocket.h b/src/symsocket.h index aa6cef0..5c32517 100644 --- a/src/symsocket.h +++ b/src/symsocket.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.4 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.3 2008/03/02 10:37:56 james * *** empty log message *** * @@ -26,7 +29,8 @@ #ifndef __SYMSOCKET_H__ #define __SYMSOCKET_H__ -typedef struct { +typedef struct +{ int fd; Slide *read_buf; diff --git a/src/terminal.c b/src/terminal.c index ca317b7..65ec41c 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.14 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.13 2008/03/02 10:37:56 james * *** empty log message *** * @@ -73,7 +76,8 @@ static char rcsid[] = #include "project.h" -typedef struct TERMINAL_struct { +typedef struct TERMINAL_struct +{ TTY_SIGNATURE; struct termios orig_termios; struct TERMINAL_struct *next; @@ -156,13 +160,16 @@ terminal_getsize (TTY * _t) if (!t) return; - if (ioctl (t->wfd, TIOCGWINSZ, &sz)) { - t->size.x = CRT_COLS; - t->size.y = CRT_ROWS; - } else { - t->size.x = sz.ws_col; - t->size.y = sz.ws_row; - } + if (ioctl (t->wfd, TIOCGWINSZ, &sz)) + { + t->size.x = CRT_COLS; + t->size.y = CRT_ROWS; + } + else + { + t->size.x = sz.ws_col; + t->size.y = sz.ws_row; + } } @@ -192,18 +199,19 @@ terminal_read (TTY * _t, void *buf, int len) terminal_dispatch (); set_nonblocking (t->rfd); - do { + do + { - red = wrap_read (t->rfd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->rfd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -221,19 +229,20 @@ terminal_write (TTY * _t, void *buf, int len) set_blocking (t->wfd); - do { + do + { - writ = wrap_write (t->wfd, buf, len); - if (writ < 0) - return -1; + writ = wrap_write (t->wfd, buf, len); + if (writ < 0) + return -1; - if (!writ) - usleep (1000); + if (!writ) + usleep (1000); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); diff --git a/src/tty.c b/src/tty.c index b7ebd19..366223e 100644 --- a/src/tty.c +++ b/src/tty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.21 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.20 2008/03/02 10:37:56 james * *** empty log message *** * @@ -72,84 +75,85 @@ static char rcsid[] = "$Id$"; static int speed_t_to_baud (speed_t s) { - switch (s) { + switch (s) + { #ifdef B0 - case B0: - return 0; + case B0: + return 0; #endif #ifdef B50 - case B50: - return 50; + case B50: + return 50; #endif #ifdef B75 - case B75: - return 75; + case B75: + return 75; #endif #ifdef B110 - case B110: - return 110; + case B110: + return 110; #endif #ifdef B134 - case B134: - return 134; + case B134: + return 134; #endif #ifdef B150 - case B150: - return 150; + case B150: + return 150; #endif #ifdef B200 - case B200: - return 200; + case B200: + return 200; #endif #ifdef B300 - case B300: - return 300; + case B300: + return 300; #endif #ifdef B600 - case B600: - return 600; + case B600: + return 600; #endif #ifdef B1200 - case B1200: - return 1200; + case B1200: + return 1200; #endif #ifdef B1800 - case B1800: - return 1800; + case B1800: + return 1800; #endif #ifdef B2400 - case B2400: - return 2400; + case B2400: + return 2400; #endif #ifdef B4800 - case B4800: - return 4800; + case B4800: + return 4800; #endif #ifdef B9600 - case B9600: - return 9600; + case B9600: + return 9600; #endif #ifdef B19200 - case B19200: - return 19200; + case B19200: + return 19200; #endif #ifdef B38400 - case B38400: - return 38400; + case B38400: + return 38400; #endif #ifdef B57600 - case B57600: - return 57600; + case B57600: + return 57600; #endif #ifdef B115200 - case B115200: - return 115200; + case B115200: + return 115200; #endif #ifdef B230400 - case B230400: - return 230400; + case B230400: + return 230400; #endif - } + } return -1; } @@ -157,84 +161,85 @@ speed_t_to_baud (speed_t s) static speed_t baud_to_speed_t (int baud) { - switch (baud) { + switch (baud) + { #ifdef B0 - case 0: - return B0; + case 0: + return B0; #endif #ifdef B50 - case 50: - return B50; + case 50: + return B50; #endif #ifdef B75 - case 75: - return B75; + case 75: + return B75; #endif #ifdef B110 - case 110: - return B110; + case 110: + return B110; #endif #ifdef B134 - case 134: - return B134; + case 134: + return B134; #endif #ifdef B150 - case 150: - return B150; + case 150: + return B150; #endif #ifdef B200 - case 200: - return B200; + case 200: + return B200; #endif #ifdef B300 - case 300: - return B300; + case 300: + return B300; #endif #ifdef B600 - case 600: - return B600; + case 600: + return B600; #endif #ifdef B1200 - case 1200: - return B1200; + case 1200: + return B1200; #endif #ifdef B1800 - case 1800: - return B1800; + case 1800: + return B1800; #endif #ifdef B2400 - case 2400: - return B2400; + case 2400: + return B2400; #endif #ifdef B4800 - case 4800: - return B4800; + case 4800: + return B4800; #endif #ifdef B9600 - case 9600: - return B9600; + case 9600: + return B9600; #endif #ifdef B19200 - case 19200: - return B19200; + case 19200: + return B19200; #endif #ifdef B38400 - case 38400: - return B38400; + case 38400: + return B38400; #endif #ifdef B57600 - case 57600: - return B57600; + case 57600: + return B57600; #endif #ifdef B115200 - case 115200: - return B115200; + case 115200: + return B115200; #endif #ifdef B230400 - case 230400: - return B230400; + case 230400: + return B230400; #endif - } + } return -1; } @@ -244,16 +249,18 @@ tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds) int line; struct timeval now, dif; - if (t->hanging_up) { - - gettimeofday (&now, NULL); - timersub (&now, &t->hangup_clock, &dif); - if (dif.tv_sec) { - line = TIOCM_DTR; - ioctl (t->rfd, TIOCMBIS, &line); - t->hanging_up = 0; + if (t->hanging_up) + { + + gettimeofday (&now, NULL); + timersub (&now, &t->hangup_clock, &dif); + if (dif.tv_sec) + { + line = TIOCM_DTR; + ioctl (t->rfd, TIOCMBIS, &line); + t->hanging_up = 0; + } } - } FD_SET (t->rfd, rfds); @@ -362,7 +369,8 @@ tty_winch (TTY * t, CRT_Pos size) #if 0 -typedef struct { +typedef struct +{ int in_dle; int in_errmark; @@ -400,28 +408,31 @@ tty_bit_analyse (Context * c, int err, int ch) bit (p, 0, zc, oc); - for (d = 1; d < 0x100; d <<= 1) { - bit (p, ch & d, zc, oc); - } + for (d = 1; d < 0x100; d <<= 1) + { + bit (p, ch & d, zc, oc); + } bit (p, 1, zc, oc); - if (err) { - p->biterrs++; - gettimeofday (&p->lasterr, NULL); - } + if (err) + { + p->biterrs++; + gettimeofday (&p->lasterr, NULL); + } - if (p->biterrs) { - log_f (c->l, - "", - ch & 0x01 ? 1 : 0, ch & 0x02 ? 1 : 0, ch & 0x04 ? 1 : 0, - ch & 0x08 ? 1 : 0, ch & 0x10 ? 1 : 0, ch & 0x20 ? 1 : 0, - ch & 0x40 ? 1 : 0, ch & 0x80 ? 1 : 0, p->bitfreq[0], - p->bitfreq[1], p->bitfreq[2], p->bitfreq[3], p->bitfreq[4], - p->bitfreq[5], p->bitfreq[6], p->bitfreq[7], p->bitfreq[8], - p->bitfreq[9]); - } + if (p->biterrs) + { + log_f (c->l, + "", + ch & 0x01 ? 1 : 0, ch & 0x02 ? 1 : 0, ch & 0x04 ? 1 : 0, + ch & 0x08 ? 1 : 0, ch & 0x10 ? 1 : 0, ch & 0x20 ? 1 : 0, + ch & 0x40 ? 1 : 0, ch & 0x80 ? 1 : 0, p->bitfreq[0], + p->bitfreq[1], p->bitfreq[2], p->bitfreq[3], p->bitfreq[4], + p->bitfreq[5], p->bitfreq[6], p->bitfreq[7], p->bitfreq[8], + p->bitfreq[9]); + } } @@ -441,54 +452,64 @@ tty_analyse (Context * c) struct timeval now, dif; int i, j, max; - if (!p->biterrs) { - p->guessed_baud = 0; - return; - } + if (!p->biterrs) + { + p->guessed_baud = 0; + return; + } gettimeofday (&now, NULL); timersub (&now, &p->lasterr, &dif); - if (dif.tv_sec > 10) { - tty_parse_reset (c); - return; - } + if (dif.tv_sec > 10) + { + tty_parse_reset (c); + return; + } max = -1; j = 0; - for (i = 0; i < TTY_BITFREQ_LEN; ++i) { - if (p->bitfreq[i] > max) { - max = p->bitfreq[i]; - j = i; + for (i = 0; i < TTY_BITFREQ_LEN; ++i) + { + if (p->bitfreq[i] > max) + { + max = p->bitfreq[i]; + j = i; + } } - } if (c->t) i = tty_get_baud (c->t); else i = -1; - if (j == 1) { - /*Closest bit edge is one bit, so the baud rate is too low */ - p->guessed_baud = -1; + if (j == 1) + { + /*Closest bit edge is one bit, so the baud rate is too low */ + p->guessed_baud = -1; - } else { - if (i > 0) - p->guessed_baud = i / j; - else - p->guessed_baud = 0; + } + else + { + if (i > 0) + p->guessed_baud = i / j; + else + p->guessed_baud = 0; - } + } - if (p->guessed_baud == -1) { - log_f (c->l, "", - p->biterrs, i); - } else { - log_f (c->l, "", - p->biterrs, i, p->guessed_baud); - } + if (p->guessed_baud == -1) + { + log_f (c->l, "", + p->biterrs, i); + } + else + { + log_f (c->l, "", + p->biterrs, i, p->guessed_baud); + } } @@ -511,47 +532,56 @@ tty_parse (Context * c, uint8_t * buf, int len) p = c->tp; - while (len--) { - - if (p->in_dle) { - p->in_dle = 0; - switch (*buf) { - case DLE: - tty_bit_analyse (c, 0, *buf); - utf8_parse (c, *buf); - break; - case 0: - p->in_errmark = 1; - break; - default: - log_f (c->l, "%s:%d DLE parsing error: \\377 \\%03o", __FILE__, - __LINE__, *buf); - } - } else if (p->in_errmark) { - p->in_errmark = 0; - - log_f (c->l, "", - __FILE__, __LINE__, *buf); - - tty_bit_analyse (c, 1, *buf); - - tty_analyse (c); - - utf8_parse (c, *buf); - - utf8_parse (c, SYM_CHAR_RESET); - - } else if (*buf == DLE) { - p->in_dle = 1; - - } else { - tty_bit_analyse (c, 0, *buf); - - tty_analyse (c); - - utf8_parse (c, *buf); - + while (len--) + { + + if (p->in_dle) + { + p->in_dle = 0; + switch (*buf) + { + case DLE: + tty_bit_analyse (c, 0, *buf); + utf8_parse (c, *buf); + break; + case 0: + p->in_errmark = 1; + break; + default: + log_f (c->l, "%s:%d DLE parsing error: \\377 \\%03o", __FILE__, + __LINE__, *buf); + } + } + else if (p->in_errmark) + { + p->in_errmark = 0; + + log_f (c->l, "", + __FILE__, __LINE__, *buf); + + tty_bit_analyse (c, 1, *buf); + + tty_analyse (c); + + utf8_parse (c, *buf); + + utf8_parse (c, SYM_CHAR_RESET); + + } + else if (*buf == DLE) + { + p->in_dle = 1; + + } + else + { + tty_bit_analyse (c, 0, *buf); + + tty_analyse (c); + + utf8_parse (c, *buf); + + } + buf++; } - buf++; - } } diff --git a/src/tty.h b/src/tty.h index 427fabb..0766212 100644 --- a/src/tty.h +++ b/src/tty.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.14 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.13 2008/03/02 10:37:56 james * *** empty log message *** * @@ -75,7 +78,8 @@ #define TTY_BITFREQ_LEN 10 -typedef struct { +typedef struct +{ int in_dle; int in_errmark; @@ -87,11 +91,13 @@ typedef struct { } TTY_Parser; -typedef struct TTY_struct { +typedef struct TTY_struct +{ TTY_SIGNATURE; } TTY; -typedef struct { +typedef struct +{ int lines; int blocked; struct termios termios; diff --git a/src/utf8.c b/src/utf8.c index d1a36d8..137f700 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.11 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.10 2008/03/02 10:37:56 james * *** empty log message *** * @@ -51,24 +54,25 @@ utf8_flush (Context * c) UTF8 *u = c->u; int i; - switch (u->utf_ptr) { - case 1: - log_f (c->l, "", u->utf_buf[0]); - break; - case 2: - log_f (c->l, "", - u->utf_buf[0], u->utf_buf[1]); - break; - case 3: - log_f (c->l, "", - u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]); - break; - case 4: - log_f (c->l, - "", - u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]); - break; - } + switch (u->utf_ptr) + { + case 1: + log_f (c->l, "", u->utf_buf[0]); + break; + case 2: + log_f (c->l, "", + u->utf_buf[0], u->utf_buf[1]); + break; + case 3: + log_f (c->l, "", + u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]); + break; + case 4: + log_f (c->l, + "", + u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]); + break; + } for (i = 0; i < u->utf_ptr; ++i) vt102_parse_char (c, u->utf_buf[i]); @@ -82,52 +86,68 @@ utf8_parse (Context * c, uint32_t ch) { UTF8 *u = c->u; - if (ch == SYM_CHAR_RESET) { - u->in_utf8 = 0; - vt102_parse_char (c, ch); - return; - } - - 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) { /*CSI, not a valid utf8 start char */ - vt102_parse_char (c, ch); - } else if ((ch & 0xe0) == 0xc0) { /*Start of two byte unicode sequence */ - u->in_utf8 = 1; - u->utf_ptr = 0; - u->utf_buf[u->utf_ptr++] = ch; - u->ch = (ch & 0x1f) << 6; - u->sh = 0; - } else if ((ch & 0xf0) == 0xe0) { /*Start of three byte unicode sequence */ - u->in_utf8 = 2; - u->utf_ptr = 0; - u->utf_buf[u->utf_ptr++] = ch; - u->ch = (ch & 0x0f) << 12; - u->sh = 6; - } else if ((ch & 0xf8) == 0xf0) { - u->in_utf8 = 3; - u->utf_ptr = 0; - u->utf_buf[u->utf_ptr++] = ch; - u->ch = (ch & 0x07) << 18; - u->sh = 12; - } else { + if (ch == SYM_CHAR_RESET) + { + u->in_utf8 = 0; vt102_parse_char (c, ch); + return; } - } else { - if ((ch & 0xc0) != 0x80) { - utf8_flush (c); - vt102_parse_char (c, ch); - } else { - u->utf_buf[u->utf_ptr++] = ch; - u->ch |= (ch & 0x3f) << u->sh; - u->sh -= 6; - u->in_utf8--; - - if (!u->in_utf8) - vt102_parse_char (c, u->ch); + + 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) + { /*CSI, not a valid utf8 start char */ + vt102_parse_char (c, ch); + } + else if ((ch & 0xe0) == 0xc0) + { /*Start of two byte unicode sequence */ + u->in_utf8 = 1; + u->utf_ptr = 0; + u->utf_buf[u->utf_ptr++] = ch; + u->ch = (ch & 0x1f) << 6; + u->sh = 0; + } + else if ((ch & 0xf0) == 0xe0) + { /*Start of three byte unicode sequence */ + u->in_utf8 = 2; + u->utf_ptr = 0; + u->utf_buf[u->utf_ptr++] = ch; + u->ch = (ch & 0x0f) << 12; + u->sh = 6; + } + else if ((ch & 0xf8) == 0xf0) + { + u->in_utf8 = 3; + u->utf_ptr = 0; + u->utf_buf[u->utf_ptr++] = ch; + u->ch = (ch & 0x07) << 18; + u->sh = 12; + } + else + { + vt102_parse_char (c, ch); + } + } + else + { + if ((ch & 0xc0) != 0x80) + { + utf8_flush (c); + vt102_parse_char (c, ch); + } + else + { + u->utf_buf[u->utf_ptr++] = ch; + u->ch |= (ch & 0x3f) << u->sh; + u->sh -= 6; + u->in_utf8--; + + if (!u->in_utf8) + vt102_parse_char (c, u->ch); + } } - } } @@ -147,25 +167,32 @@ int utf8_encode (char *ptr, int ch) { - if (ch < 0x80) { - ptr[0] = ch; - return 1; - } else if (ch < 0x800) { - ptr[0] = 0xc0 | (ch >> 6); - ptr[1] = 0x80 | (ch & 0x3f); - return 2; - } else if (ch < 0x10000) { - ptr[0] = 0xe0 | (ch >> 12); - ptr[1] = 0x80 | ((ch >> 6) & 0x3f); - ptr[2] = 0x80 | (ch & 0x3f); - return 3; - } else if (ch < 0x1fffff) { - ptr[0] = 0xf0 | (ch >> 18); - ptr[1] = 0x80 | ((ch >> 12) & 0x3f); - ptr[2] = 0x80 | ((ch >> 6) & 0x3f); - ptr[3] = 0x80 | (ch & 0x3f); - return 4; - } + if (ch < 0x80) + { + ptr[0] = ch; + return 1; + } + else if (ch < 0x800) + { + ptr[0] = 0xc0 | (ch >> 6); + ptr[1] = 0x80 | (ch & 0x3f); + return 2; + } + else if (ch < 0x10000) + { + ptr[0] = 0xe0 | (ch >> 12); + ptr[1] = 0x80 | ((ch >> 6) & 0x3f); + ptr[2] = 0x80 | (ch & 0x3f); + return 3; + } + else if (ch < 0x1fffff) + { + ptr[0] = 0xf0 | (ch >> 18); + ptr[1] = 0x80 | ((ch >> 12) & 0x3f); + ptr[2] = 0x80 | ((ch >> 6) & 0x3f); + ptr[3] = 0x80 | (ch & 0x3f); + return 4; + } return 0; } diff --git a/src/utf8.h b/src/utf8.h index 651dc1e..f09e2cb 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.6 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.5 2008/03/02 10:37:56 james * *** empty log message *** * @@ -34,7 +37,8 @@ #define __UTF8_H__ -typedef struct { +typedef struct +{ int in_utf8; uint8_t utf_buf[4]; diff --git a/src/vt102.c b/src/vt102.c index a10e025..ff66f49 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -6,10 +6,14 @@ * */ -static char rcsid[] = "$Id$"; +static char rcsid[] = + "$Id$"; /* * $Log$ + * Revision 1.56 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.55 2008/03/02 12:32:57 staffcvs * *** empty log message *** * @@ -424,10 +428,11 @@ vt102_crt_update (Context * c) v->crt.hide_cursor = v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1; - if (v->current_line.y != v->pos.y) { - vt102_log_line (c, v->current_line.y); - v->current_line = v->pos; - } + if (v->current_line.y != v->pos.y) + { + vt102_log_line (c, v->current_line.y); + v->current_line = v->pos; + } if (c->d) cmd_show_status (c->d, c); @@ -468,17 +473,19 @@ vt102_log_line (Context * c, int line) return; - for (; e.x > 0; --e.x) { - if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ') - break; - } - - for (; p.x <= e.x; ++p.x) { - int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr; - if (ch < 32) - ch = ' '; - logptr += utf8_encode (logptr, ch); - } + for (; e.x > 0; --e.x) + { + if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ') + break; + } + + for (; p.x <= e.x; ++p.x) + { + int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr; + if (ch < 32) + ch = ' '; + logptr += utf8_encode (logptr, ch); + } *logptr = 0; c->l->log (c->l, logbuf); @@ -516,11 +523,14 @@ vt102_cursor_normalize (VT102 * v) { CRT_Pos *top, *bottom; - if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) { - vt102_clip_cursor (v, v->top_margin, v->bottom_margin); - } else { - vt102_clip_cursor (v, v->screen_start, v->screen_end); - } + if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) + { + vt102_clip_cursor (v, v->top_margin, v->bottom_margin); + } + else + { + vt102_clip_cursor (v, v->screen_start, v->screen_end); + } } @@ -540,14 +550,15 @@ vt102_cursor_advance_line (Context * c) /*have wraped off end of last line in scrolling region */ /* (|| not necessary, but shuts compiler up */ if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) && - (couldscroll)) { - vt102_log_line (c, v->pos.y); + (couldscroll)) + { + vt102_log_line (c, v->pos.y); - vt102_history (c, v->top_margin, v->bottom_margin); + vt102_history (c, v->top_margin, v->bottom_margin); - crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); - return; - } + crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); + return; + } if (v->pos.y != v->screen_end.y) v->pos.y++; @@ -564,12 +575,13 @@ vt102_cursor_retreat_line (Context * c) /*have wraped off end of last line in scrolling region */ /* (|| not necessary, but shuts compiler up */ if (((v->pos.y == v->top_margin.y) || (v->pos.y == v->screen_start.y)) && - (couldscroll)) { - vt102_log_line (c, v->pos.y); + (couldscroll)) + { + vt102_log_line (c, v->pos.y); - crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); - return; - } + crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); + return; + } if (v->pos.y != v->screen_start.y) v->pos.y--; @@ -600,11 +612,14 @@ vt102_do_pending_wrap (Context * c) if ((v->pos.y == v->screen_end.y) && (!couldscroll)) return; - if (couldscroll) { - v->pos.x = v->top_margin.x; - } else { - v->pos.x = 0; - } + if (couldscroll) + { + v->pos.x = v->top_margin.x; + } + else + { + v->pos.x = 0; + } vt102_cursor_advance_line (c); } @@ -614,12 +629,13 @@ vt102_cursor_advance (Context * c) { VT102 *v = c->v; - if (v->pos.x < v->bottom_margin.x) { + if (v->pos.x < v->bottom_margin.x) + { /*Normal advance*/ - v->pos.x++; - v->pending_wrap = 0; - return; - } + v->pos.x++; + v->pending_wrap = 0; + return; + } v->pending_wrap++; if (!c->v->xn_glitch) vt102_do_pending_wrap (c); @@ -630,9 +646,10 @@ vt102_cursor_advance (Context * c) void vt102_cursor_retreat (VT102 * v) { - if (v->pos.x != v->top_margin.x) { - v->pos.x--; - } + if (v->pos.x != v->top_margin.x) + { + v->pos.x--; + } v->pending_wrap = 0; } @@ -644,20 +661,22 @@ vt102_reset_tabs (VT102 * v) memset (v->tabs, 0, sizeof (v->tabs)); - for (i = 0; i < VT102_MAX_COLS; i += 8) { - v->tabs[i]++; - } + for (i = 0; i < VT102_MAX_COLS; i += 8) + { + v->tabs[i]++; + } } void vt102_cursor_advance_tab (VT102 * v) { if (v->pos.x == v->bottom_margin.x) return; - while (v->pos.x < v->bottom_margin.x) { - v->pos.x++; - if (v->tabs[v->pos.x]) - break; - } + while (v->pos.x < v->bottom_margin.x) + { + v->pos.x++; + if (v->tabs[v->pos.x]) + break; + } v->pending_wrap = 0; } @@ -666,11 +685,12 @@ vt102_cursor_retreat_tab (VT102 * v) { if (v->pos.x == v->top_margin.x) return; - while (v->pos.x > v->top_margin.x) { - v->pos.x--; - if (v->tabs[v->pos.x]) - break; - } + while (v->pos.x > v->top_margin.x) + { + v->pos.x--; + if (v->tabs[v->pos.x]) + break; + } v->pending_wrap = 0; } @@ -684,13 +704,16 @@ vt102_cursor_home (VT102 * v) vt102_cursor_absolute (VT102 * v, int x, int y) { - if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) { - v->pos.x = x + v->top_margin.x; - v->pos.y = y + v->top_margin.y; - } else { - v->pos.x = x; - v->pos.y = y; - } + if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) + { + v->pos.x = x + v->top_margin.x; + v->pos.y = y + v->top_margin.y; + } + else + { + v->pos.x = x; + v->pos.y = y; + } vt102_cursor_normalize (v); v->pending_wrap = 0; } @@ -713,11 +736,12 @@ vt102_delete_from_line (VT102 * v, CRT_Pos p) if (n < 0) return; - if (n) { + if (n) + { - memmove (&v->crt.screen[CRT_ADDR_POS (&p)], - &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n); - } + memmove (&v->crt.screen[CRT_ADDR_POS (&p)], + &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n); + } v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' '; /*But not attr due to vt102 bug*/ @@ -731,11 +755,12 @@ vt102_insert_into_line (VT102 * v, CRT_Pos p) if (n < 0) return; - if (n) { + if (n) + { - memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1], - &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n); - } + memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1], + &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n); + } v->crt.screen[CRT_ADDR_POS (&p)].chr = ' '; v->crt.screen[CRT_ADDR_POS (&p)].attr = CRT_ATTR_NORMAL; @@ -751,44 +776,50 @@ vt102_change_mode (Context * c, int private, char *ns, int set) int m; - if (*ns) { - m = atoi (ns); - } else { - m = 1; - } + if (*ns) + { + m = atoi (ns); + } + else + { + m = 1; + } if (m < 0) return; if (m >= VT102_NMODES) return; - if (private) { - v->private_modes[m] = set; - switch (m) { - case VT102_PRIVATE_MODE_CURSOR_MODE: - if (v->application_keypad_mode) - v->private_modes[m] = 0; + if (private) + { + v->private_modes[m] = set; + switch (m) + { + case VT102_PRIVATE_MODE_CURSOR_MODE: + if (v->application_keypad_mode) + v->private_modes[m] = 0; #if 0 - fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n", - v->private_modes[m], set); + fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n", + v->private_modes[m], set); #endif - break; - case VT102_PRIVATE_MODE_ORIGIN_MODE: - vt102_cursor_home (v); - break; - case VT102_PRIVATE_MODE_132COLS: - /* We don't implement 132 col mode - yet */ + break; + case VT102_PRIVATE_MODE_ORIGIN_MODE: + vt102_cursor_home (v); + break; + case VT102_PRIVATE_MODE_132COLS: + /* We don't implement 132 col mode - yet */ - v->current_size.x = - v-> - private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 : - VT102_COLS_80; + v->current_size.x = + v-> + private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 : + VT102_COLS_80; - vt102_do_resize (c); - break; - } + vt102_do_resize (c); + break; + } - } else + } + else v->modes[m] = set; #if 0 @@ -810,33 +841,36 @@ vt102_parse_mode_string (Context * c, char *buf, int len) len--; - if (*buf == '?') { - private++; - buf++; - len--; - } + if (*buf == '?') + { + private++; + buf++; + len--; + } if (len < 0) return; - while (len--) { - if (*buf == ';') { - vt102_change_mode (c, private, &num[o], last == 'h'); - memset (num, 0, sizeof (num)); - o = sizeof (num) - 1; - buf++; - continue; - } + while (len--) + { + if (*buf == ';') + { + vt102_change_mode (c, private, &num[o], last == 'h'); + memset (num, 0, sizeof (num)); + o = sizeof (num) - 1; + buf++; + continue; + } - num[0] = num[1]; - num[1] = num[2]; - num[2] = *buf; + num[0] = num[1]; + num[1] = num[2]; + num[2] = *buf; - if (o) - o--; + if (o) + o--; - buf++; - } + buf++; + } vt102_change_mode (c, private, &num[o], last == 'h'); @@ -849,111 +883,115 @@ vt102_change_attr (VT102 * v, char *na) int a; - if (*na) { - a = atoi (na); - } else { - a = 0; - } - - switch (a) { - case 0: - v->attr = CRT_ATTR_NORMAL; - v->color = CRT_COLOR_NORMAL; - break; - case 1: - v->attr |= CRT_ATTR_BOLD; - break; - case 21: - case 22: - v->attr &= ~CRT_ATTR_BOLD; - break; - case 4: - v->attr |= CRT_ATTR_UNDERLINE; - break; - case 24: - v->attr &= ~CRT_ATTR_UNDERLINE; - break; - case 5: - v->attr |= CRT_ATTR_BLINK; - break; - case 25: - v->attr &= ~CRT_ATTR_BLINK; - break; - case 7: - v->attr |= CRT_ATTR_REVERSE; - break; - case 27: - v->attr &= ~CRT_ATTR_REVERSE; - break; - case 30: - case 31: - case 32: - case 33: - case 34: - case 35: - case 36: - case 37: - v->color &= ~CRT_COLOR_FG_MASK; - v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; - break; - case 90: - case 91: - case 92: - case 93: - case 94: - case 95: - case 96: - case 97: - v->color &= ~CRT_COLOR_FG_MASK; - v->color |= - (((a - - 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) & - CRT_COLOR_FG_MASK; - break; - case 39: - case 99: - v->color &= ~CRT_COLOR_FG_MASK; - v->color |= - (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; - break; - case 40: - case 41: - case 42: - case 43: - case 44: - case 45: - case 46: - case 47: - v->color &= ~CRT_COLOR_BG_MASK; - v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; - break; - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - case 106: - case 107: - v->color &= ~CRT_COLOR_BG_MASK; - v->color |= - (((a - - 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) & - CRT_COLOR_BG_MASK; - break; - case 49: - case 109: - v->color &= ~CRT_COLOR_BG_MASK; - v->color |= - (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; - break; - - default: - ; + if (*na) + { + a = atoi (na); + } + else + { + a = 0; + } + + switch (a) + { + case 0: + v->attr = CRT_ATTR_NORMAL; + v->color = CRT_COLOR_NORMAL; + break; + case 1: + v->attr |= CRT_ATTR_BOLD; + break; + case 21: + case 22: + v->attr &= ~CRT_ATTR_BOLD; + break; + case 4: + v->attr |= CRT_ATTR_UNDERLINE; + break; + case 24: + v->attr &= ~CRT_ATTR_UNDERLINE; + break; + case 5: + v->attr |= CRT_ATTR_BLINK; + break; + case 25: + v->attr &= ~CRT_ATTR_BLINK; + break; + case 7: + v->attr |= CRT_ATTR_REVERSE; + break; + case 27: + v->attr &= ~CRT_ATTR_REVERSE; + break; + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + v->color &= ~CRT_COLOR_FG_MASK; + v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; + break; + case 90: + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: + v->color &= ~CRT_COLOR_FG_MASK; + v->color |= + (((a - + 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) & + CRT_COLOR_FG_MASK; + break; + case 39: + case 99: + v->color &= ~CRT_COLOR_FG_MASK; + v->color |= + (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; + break; + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + v->color &= ~CRT_COLOR_BG_MASK; + v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; + break; + case 100: + case 101: + case 102: + case 103: + case 104: + case 105: + case 106: + case 107: + v->color &= ~CRT_COLOR_BG_MASK; + v->color |= + (((a - + 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) & + CRT_COLOR_BG_MASK; + break; + case 49: + case 109: + v->color &= ~CRT_COLOR_BG_MASK; + v->color |= + (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; + break; + + default: + ; #if 0 - fprintf (stderr, "unhandled SGR %d\n", a); + fprintf (stderr, "unhandled SGR %d\n", a); #endif - } + } } @@ -974,24 +1012,26 @@ vt102_parse_attr_string (VT102 * v, char *buf, int len) if (len < 0) return; - while (len--) { - if (*buf == ';') { - vt102_change_attr (v, &num[o]); - memset (num, 0, sizeof (num)); - o = sizeof (num) - 1; - buf++; - continue; - } + while (len--) + { + if (*buf == ';') + { + vt102_change_attr (v, &num[o]); + memset (num, 0, sizeof (num)); + o = sizeof (num) - 1; + buf++; + continue; + } - num[0] = num[1]; - num[1] = num[2]; - num[2] = *buf; + num[0] = num[1]; + num[1] = num[2]; + num[2] = *buf; - if (o) - o--; + if (o) + o--; - buf++; - } + buf++; + } vt102_change_attr (v, &num[o]); } @@ -1029,14 +1069,18 @@ vt102_regular_char (Context * c, VT102 * v, uint32_t ch) v->last_reg_char = ch; - if (ch < VT102_CHARSET_SIZE) { - int cs; - if ((cs = vt102_charset_c0[ch])) { - ch = cs; - } else if ((cs = charset_from_csid[v->g[v->cs]][ch])) { - ch = cs; + if (ch < VT102_CHARSET_SIZE) + { + int cs; + if ((cs = vt102_charset_c0[ch])) + { + ch = cs; + } + else if ((cs = charset_from_csid[v->g[v->cs]][ch])) + { + ch = cs; + } } - } v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch; v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr; v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color; @@ -1047,10 +1091,11 @@ vt102_regular_char (Context * c, VT102 * v, uint32_t ch) vt102_send_id (Context * c, char *buf) { - if (c->t) { - int l = strlen (buf); - c->t->xmit (c->t, buf, l); - } + if (c->t) + { + int l = strlen (buf); + c->t->xmit (c->t, buf, l); + } } void @@ -1060,28 +1105,30 @@ vt102_scs (Context * c, int g, int s) int cs = VT102_CSID_US; - switch (s) { - case 'A': - cs = VT102_CSID_UK; - break; - case '1': - case '2': - case 'B': - cs = VT102_CSID_US; - break; - case '0': - cs = VT102_CSID_GL; - break; - } - - switch (g) { - case '(': - v->g[0] = cs; - break; - case ')': - v->g[1] = cs; - break; - } + switch (s) + { + case 'A': + cs = VT102_CSID_UK; + break; + case '1': + case '2': + case 'B': + cs = VT102_CSID_US; + break; + case '0': + cs = VT102_CSID_GL; + break; + } + + switch (g) + { + case '(': + v->g[0] = cs; + break; + case ')': + v->g[1] = cs; + break; + } } @@ -1102,258 +1149,279 @@ vt102_parse_csi (Context * c, char *buf, int len) buf[len - 1] = 0; #endif - if (len > 2) { - narg = atoi (arg); - } else { - narg = 1; - } - - switch (buf[0]) { - case '[': - switch (last) { - case '@': - while (narg--) - vt102_insert_into_line (v, v->pos); - break; - case 'A': - vt102_cursor_relative (v, 0, -narg); - break; - case 'e': - case 'B': - vt102_cursor_relative (v, 0, narg); - break; - case 'a': - case 'C': - vt102_cursor_relative (v, narg, 0); - break; - case 'D': - vt102_cursor_relative (v, -narg, 0); - break; - case 'E': - vt102_cursor_relative (v, 0, narg); - vt102_cursor_carriage_return (v); - break; - case 'F': - vt102_cursor_relative (v, 0, -narg); - vt102_cursor_carriage_return (v); - break; - case 'G': - vt102_cursor_absolute (v, narg - 1, v->pos.y); - break; - case 'H': - case 'f': - { - int x, y; + if (len > 2) + { + narg = atoi (arg); + } + else + { + narg = 1; + } - y = narg - 1; + switch (buf[0]) + { + case '[': + switch (last) + { + case '@': + while (narg--) + vt102_insert_into_line (v, v->pos); + break; + case 'A': + vt102_cursor_relative (v, 0, -narg); + break; + case 'e': + case 'B': + vt102_cursor_relative (v, 0, narg); + break; + case 'a': + case 'C': + vt102_cursor_relative (v, narg, 0); + break; + case 'D': + vt102_cursor_relative (v, -narg, 0); + break; + case 'E': + vt102_cursor_relative (v, 0, narg); + vt102_cursor_carriage_return (v); + break; + case 'F': + vt102_cursor_relative (v, 0, -narg); + vt102_cursor_carriage_return (v); + break; + case 'G': + vt102_cursor_absolute (v, narg - 1, v->pos.y); + break; + case 'H': + case 'f': + { + int x, y; - ptr = index (arg, ';'); - if (ptr) - x = atoi (ptr + 1) - 1; - else - x = 0; + y = narg - 1; - vt102_cursor_absolute (v, x, y); - } - break; - case 'I': - while (narg--) - vt102_cursor_advance_tab (c->v); - break; - case 'J': - if (len == 2) - narg = 0; /*Different default */ - switch (narg) { - case 0: - crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); - break; - case 1: - crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color); - break; - case 2: - crt_erase (&v->crt, v->screen_start, v->screen_end, 1, v->color); - break; - } - break; - case 'K': - { - CRT_Pos ls = { 0, v->pos.y }; - CRT_Pos le = { v->current_size.x - 1, v->pos.y }; - if (len == 2) - narg = 0; /*Different default */ + ptr = index (arg, ';'); + if (ptr) + x = atoi (ptr + 1) - 1; + else + x = 0; - switch (narg) { - case 0: - crt_erase (&v->crt, v->pos, le, 1, v->color); + vt102_cursor_absolute (v, x, y); + } break; - case 1: - crt_erase (&v->crt, ls, v->pos, 1, v->color); + case 'I': + while (narg--) + vt102_cursor_advance_tab (c->v); break; - case 2: - crt_erase (&v->crt, ls, le, 1, v->color); + case 'J': + if (len == 2) + narg = 0; /*Different default */ + switch (narg) + { + case 0: + crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); + break; + case 1: + crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color); + break; + case 2: + crt_erase (&v->crt, v->screen_start, v->screen_end, 1, + v->color); + break; + } + break; + case 'K': + { + CRT_Pos ls = { 0, v->pos.y }; + CRT_Pos le = { v->current_size.x - 1, v->pos.y }; + if (len == 2) + narg = 0; /*Different default */ + + switch (narg) + { + case 0: + crt_erase (&v->crt, v->pos, le, 1, v->color); + break; + case 1: + crt_erase (&v->crt, ls, v->pos, 1, v->color); + break; + case 2: + crt_erase (&v->crt, ls, le, 1, v->color); + break; + } + } break; - } - } - break; - - case 'L': - if ((v->pos.y >= v->top_margin.y) - && (v->pos.y <= v->bottom_margin.y)) { - while (narg--) - crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1, v->color); - } - break; - case 'M': - if ((v->pos.y >= v->top_margin.y) - && (v->pos.y <= v->bottom_margin.y)) { - while (narg--) { - vt102_history (c, v->pos, v->bottom_margin); - crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1, v->color); - } - } - break; - case 'P': - while (narg--) - vt102_delete_from_line (v, v->pos); - break; - case 'S': - while (narg--) { - vt102_history (c, v->top_margin, v->bottom_margin); - crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); - } - break; - case 'T': - while (narg--) - crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, - v->color); - break; - case 'X': - { - CRT_Pos end = v->pos; - if (!narg) - narg++; + case 'L': + if ((v->pos.y >= v->top_margin.y) + && (v->pos.y <= v->bottom_margin.y)) + { + while (narg--) + crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1, + v->color); + } + break; - end.x += narg - 1; - if (end.x > v->bottom_margin.x) - end.x = v->bottom_margin.x; + case 'M': + if ((v->pos.y >= v->top_margin.y) + && (v->pos.y <= v->bottom_margin.y)) + { + while (narg--) + { + vt102_history (c, v->pos, v->bottom_margin); + crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1, + v->color); + } + } + break; + case 'P': + while (narg--) + vt102_delete_from_line (v, v->pos); + break; + case 'S': + while (narg--) + { + vt102_history (c, v->top_margin, v->bottom_margin); + crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, + v->color); + } + break; + case 'T': + while (narg--) + crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, + v->color); + break; + case 'X': + { + CRT_Pos end = v->pos; + if (!narg) + narg++; + + end.x += narg - 1; + if (end.x > v->bottom_margin.x) + end.x = v->bottom_margin.x; + + crt_erase (&v->crt, v->pos, end, 1, v->color); + } + break; + case 'Z': + while (narg--) + vt102_cursor_retreat_tab (c->v); + break; + case '`': + vt102_cursor_absolute (v, narg - 1, v->pos.y); + break; + case 'b': + while (narg--) + vt102_regular_char (c, v, v->last_reg_char); + break; + case 'c': + /* For some obscure reason some programs seem to send */ + /* CSI [ ? .. c, which we ignore */ + if (buf[1] != '?') + vt102_send_id (c, "\033[?2c"); + break; + case 'd': + vt102_cursor_absolute (v, v->pos.x, narg - 1); + break; + case 'g': + if (len == 2) + narg = 0; /*Different default */ + + switch (narg) + { + case 0: + v->tabs[v->pos.x] = 0; + break; + case 2: //FIXME: - LA120 says current line only WTF? + case 3: + memset (v->tabs, 0, sizeof (v->tabs)); + break; + } + break; - crt_erase (&v->crt, v->pos, end, 1, v->color); - } - break; - case 'Z': - while (narg--) - vt102_cursor_retreat_tab (c->v); - break; - case '`': - vt102_cursor_absolute (v, narg - 1, v->pos.y); - break; - case 'b': - while (narg--) - vt102_regular_char (c, v, v->last_reg_char); - break; - case 'c': - /* For some obscure reason some programs seem to send */ - /* CSI [ ? .. c, which we ignore */ - if (buf[1] != '?') - vt102_send_id (c, "\033[?2c"); - break; - case 'd': - vt102_cursor_absolute (v, v->pos.x, narg - 1); - break; - case 'g': - if (len == 2) - narg = 0; /*Different default */ + case 'i': //Printer commands + //FIXME + break; + case 'h': + case 'l': + vt102_parse_mode_string (c, &buf[1], len - 1); + break; - switch (narg) { - case 0: - v->tabs[v->pos.x] = 0; - break; - case 2: //FIXME: - LA120 says current line only WTF? - case 3: - memset (v->tabs, 0, sizeof (v->tabs)); - break; - } - break; - case 'i': //Printer commands - //FIXME - break; - case 'h': - case 'l': - vt102_parse_mode_string (c, &buf[1], len - 1); - break; + case 'm': + vt102_parse_attr_string (v, &buf[1], len - 1); + break; + case 'n': //Device status report + switch (buf[1]) + { + case '5': + vt102_send_id (c, "\033[0n"); + break; + case '6': + if (c->t) + { + char buf[16]; + int i; + i = + sprintf (buf, "\033[%d;%dR", v->pos.y + 1, v->pos.x + 1); + c->t->xmit (c->t, buf, i); + } + break; + default: + //?15n printer status + log_f (c->l, "<%s:%d unhandled DSR: \\033%s>", __FILE__, + __LINE__, buf); + } + break; + case 'q': //Load LED on off + break; + case 'r': + v->top_margin = v->screen_start; + v->bottom_margin = v->screen_end; + + if ((len > 2) && (ptr = index (arg, ';'))) + { + ptr++; + v->top_margin.y = narg - 1; + v->bottom_margin.y = atoi (ptr) - 1; + } + + if (v->top_margin.y < v->screen_start.y) + v->top_margin.y = v->screen_start.y; + if (v->top_margin.y > v->screen_end.y) + v->top_margin.y = v->screen_end.y; + if (v->bottom_margin.y < v->screen_start.y) + v->bottom_margin.y = v->screen_start.y; + if (v->bottom_margin.y > v->screen_end.y) + v->bottom_margin.y = v->screen_end.y; + + vt102_cursor_home (v); + break; + case 's': + v->saved.pos = v->pos; + break; + case 'u': + v->pos = v->saved.pos; + vt102_cursor_normalize (v); + v->pending_wrap = 0; + break; + case 'y': //Invoke confidence test + break; + case 'z': //request terminal parameters + break; + default: + log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__, + buf); - case 'm': - vt102_parse_attr_string (v, &buf[1], len - 1); - break; - case 'n': //Device status report - switch (buf[1]) { - case '5': - vt102_send_id (c, "\033[0n"); - break; - case '6': - if (c->t) { - char buf[16]; - int i; - i = sprintf (buf, "\033[%d;%dR", v->pos.y + 1, v->pos.x + 1); - c->t->xmit (c->t, buf, i); + ; } - break; - default: - //?15n printer status - log_f (c->l, "<%s:%d unhandled DSR: \\033%s>", __FILE__, - __LINE__, buf); - } break; - case 'q': //Load LED on off - break; - case 'r': - v->top_margin = v->screen_start; - v->bottom_margin = v->screen_end; - - if ((len > 2) && (ptr = index (arg, ';'))) { - ptr++; - v->top_margin.y = narg - 1; - v->bottom_margin.y = atoi (ptr) - 1; - } - - if (v->top_margin.y < v->screen_start.y) - v->top_margin.y = v->screen_start.y; - if (v->top_margin.y > v->screen_end.y) - v->top_margin.y = v->screen_end.y; - if (v->bottom_margin.y < v->screen_start.y) - v->bottom_margin.y = v->screen_start.y; - if (v->bottom_margin.y > v->screen_end.y) - v->bottom_margin.y = v->screen_end.y; - - vt102_cursor_home (v); - break; - case 's': - v->saved.pos = v->pos; - break; - case 'u': - v->pos = v->saved.pos; - vt102_cursor_normalize (v); - v->pending_wrap = 0; - break; - case 'y': //Invoke confidence test - break; - case 'z': //request terminal parameters - break; - default: - log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__, buf); - + log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, + __LINE__, buf); ; } - break; - default: - log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, - __LINE__, buf); - ; - } @@ -1372,62 +1440,107 @@ vt102_parse_esc (Context * c) !v->private_modes[VT102_PRIVATE_MODE_VT52], p->cmd_buf); #endif - if (!v->private_modes[VT102_PRIVATE_MODE_VT52]) { - int ate = 1; + if (!v->private_modes[VT102_PRIVATE_MODE_VT52]) + { + int ate = 1; - switch (p->cmd_buf[0]) { - case 'A': - vt102_cursor_relative (v, 0, -1); - break; - case 'B': - vt102_cursor_relative (v, 0, 1); - break; - case 'C': - vt102_cursor_relative (v, 1, 0); - break; + switch (p->cmd_buf[0]) + { + case 'A': + vt102_cursor_relative (v, 0, -1); + break; + case 'B': + vt102_cursor_relative (v, 0, 1); + break; + case 'C': + vt102_cursor_relative (v, 1, 0); + break; + case 'D': + vt102_cursor_relative (v, -1, 0); + break; + case 'F': + v->cs = 1; + v->g[1] = VT102_CSID_VT52; + break; + case 'G': + v->cs = 0; + v->g[0] = VT102_CSID_US; + break; + case 'H': + vt102_cursor_absolute (v, 0, 0); + break; + case 'I': + vt102_cursor_retreat_line (c); + break; + case 'J': + crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); + break; + case 'K': + { + CRT_Pos le = { v->current_size.x - 1, v->pos.y }; + crt_erase (&v->crt, v->pos, le, 1, v->color); + } + break; + case 'Y': + vt102_cursor_absolute (v, p->cmd_buf[2] - 040, p->cmd_buf[1] - 040); + break; + case 'V': //Print current line + break; + case 'W': //Printer on + break; + case 'X': //printer off + break; + case ']': //print screen + break; + case 'Z': //ID + vt102_send_id (c, "\033/K"); + break; + case '^': //Autoprint on + break; + case '_': //Autoprint off + break; + case '=': + v->application_keypad_mode = 1; + break; + case '>': + v->application_keypad_mode = 0; + break; + default: + ate = 0; + } + if (ate) + return; + } + + +/*If you edit this switch don't forget to edit the length and termination tables*/ + switch (p->cmd_buf[0]) + { case 'D': - vt102_cursor_relative (v, -1, 0); - break; - case 'F': - v->cs = 1; - v->g[1] = VT102_CSID_VT52; + vt102_cursor_advance_line (c); break; - case 'G': - v->cs = 0; - v->g[0] = VT102_CSID_US; + + case 'E': + vt102_cursor_advance_line (c); + v->pos.x = v->top_margin.x; + vt102_cursor_normalize (v); + v->pending_wrap = 0; break; case 'H': - vt102_cursor_absolute (v, 0, 0); + v->tabs[v->pos.x]++; break; - case 'I': + case 'M': vt102_cursor_retreat_line (c); break; - case 'J': - crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); + case 'N': //select G2 for one char break; - case 'K': - { - CRT_Pos le = { v->current_size.x - 1, v->pos.y }; - crt_erase (&v->crt, v->pos, le, 1, v->color); - } + case 'O': //select G3 for one char break; - case 'Y': - vt102_cursor_absolute (v, p->cmd_buf[2] - 040, p->cmd_buf[1] - 040); - break; - case 'V': //Print current line - break; - case 'W': //Printer on - break; - case 'X': //printer off - break; - case ']': //print screen - break; - case 'Z': //ID - vt102_send_id (c, "\033/K"); - break; - case '^': //Autoprint on + case 'Z': + vt102_send_id (c, terminal_id); break; - case '_': //Autoprint off + case 'c': + vt102_reset (c); break; case '=': v->application_keypad_mode = 1; @@ -1435,102 +1548,62 @@ vt102_parse_esc (Context * c) case '>': v->application_keypad_mode = 0; break; - default: - ate = 0; - } - if (ate) - return; - } + case '#': + switch (p->cmd_buf[1]) + { + case '3': //top of double height line + case '4': //bottom of double height line + case '5': //single width line + case '6': //double width line + break; + case '8': + /*DECALN*/ + { + int i; + crt_erase (&v->crt, v->screen_start, v->screen_end, 1, + CRT_COLOR_NORMAL); + for (i = 0; i < CRT_ADDR_POS (&v->screen_end); ++i) + v->crt.screen[i].chr = 'E'; + } + break; + default: + + log_f (c->l, + "<%s:%d unhandled ESC: \\033 \\043 \\%03o (ESC # %c)>", + __FILE__, __LINE__, p->cmd_buf[1], safe_ch (p->cmd_buf[1])); -/*If you edit this switch don't forget to edit the length and termination tables*/ - switch (p->cmd_buf[0]) { - case 'D': - vt102_cursor_advance_line (c); - break; - - case 'E': - vt102_cursor_advance_line (c); - v->pos.x = v->top_margin.x; - vt102_cursor_normalize (v); - v->pending_wrap = 0; - break; - case 'H': - v->tabs[v->pos.x]++; - break; - case 'M': - vt102_cursor_retreat_line (c); - break; - case 'N': //select G2 for one char - break; - case 'O': //select G3 for one char - break; - case 'Z': - vt102_send_id (c, terminal_id); - break; - case 'c': - vt102_reset (c); - break; - case '=': - v->application_keypad_mode = 1; - break; - case '>': - v->application_keypad_mode = 0; - break; - - case '#': - switch (p->cmd_buf[1]) { - case '3': //top of double height line - case '4': //bottom of double height line - case '5': //single width line - case '6': //double width line + } + break; + case '<': + /*Set ansi mode - ignored */ + break; + + case '7': + vt102_save_state (v); break; case '8': - /*DECALN*/ { - int i; - crt_erase (&v->crt, v->screen_start, v->screen_end, 1, - CRT_COLOR_NORMAL); - for (i = 0; i < CRT_ADDR_POS (&v->screen_end); ++i) - v->crt.screen[i].chr = 'E'; - } + vt102_restore_state (v); + break; + case ']': /*Set various titles */ + //FIXME: + break; + case '[': + vt102_parse_csi (c, p->cmd_buf, p->cmd_ptr); + break; + case '(': /*Charsets */ + case ')': + case '+': + case '*': + case '%': + vt102_scs (c, p->cmd_buf[0], p->cmd_buf[1]); break; default: + log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__, + __LINE__, p->cmd_buf[0], safe_ch (p->cmd_buf[0])); - log_f (c->l, - "<%s:%d unhandled ESC: \\033 \\043 \\%03o (ESC # %c)>", - __FILE__, __LINE__, p->cmd_buf[1], safe_ch (p->cmd_buf[1])); - + ; } - break; - case '<': - /*Set ansi mode - ignored */ - break; - - case '7': - vt102_save_state (v); - break; - case '8': - vt102_restore_state (v); - break; - case ']': /*Set various titles */ - //FIXME: - break; - case '[': - vt102_parse_csi (c, p->cmd_buf, p->cmd_ptr); - break; - case '(': /*Charsets */ - case ')': - case '+': - case '*': - case '%': - vt102_scs (c, p->cmd_buf[0], p->cmd_buf[1]); - break; - default: - log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__, - __LINE__, p->cmd_buf[0], safe_ch (p->cmd_buf[0])); - - ; - } p->cmd_buf[p->cmd_ptr] = 0; #ifdef DEBUG @@ -1545,21 +1618,23 @@ vt102_status_line (VT102 * v, char *str) int i; CRT_CA *ca = &v->crt.screen[CRT_ADDR (v->current_size.y, 0)]; - for (i = 0; i < v->current_size.x; ++i) { - ca->attr = CRT_ATTR_REVERSE; - ca->color = CRT_COLOR_NORMAL; - ca->chr = *str ? *str : ' '; - if (*str) - str++; - ca++; - } - - for (; i < VT102_MAX_COLS; ++i) { - ca->attr = CRT_ATTR_NORMAL; - ca->color = CRT_COLOR_NORMAL; - ca->chr = ' '; - ca++; - } + for (i = 0; i < v->current_size.x; ++i) + { + ca->attr = CRT_ATTR_REVERSE; + ca->color = CRT_COLOR_NORMAL; + ca->chr = *str ? *str : ' '; + if (*str) + str++; + ca++; + } + + for (; i < VT102_MAX_COLS; ++i) + { + ca->attr = CRT_ATTR_NORMAL; + ca->color = CRT_COLOR_NORMAL; + ca->chr = ' '; + ca++; + } } @@ -1616,17 +1691,19 @@ pre_parse_cmd (int ch, VT102_parser * p) p->in_cmd = 0; p->cmd_termination = vt102_cmd_termination[ch]; - if (p->cmd_termination) { - p->in_cmd++; - return; - } + if (p->cmd_termination) + { + p->in_cmd++; + return; + } p->cmd_more_bytes = vt102_cmd_length[ch]; - if (p->cmd_more_bytes) { - p->in_cmd++; - return; - } + if (p->cmd_more_bytes) + { + p->in_cmd++; + return; + } } void @@ -1643,116 +1720,215 @@ vt102_parse_char (Context * c, int ch) /* Turn anything non-ascii into '?' */ #if 0 - if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127)) { - ch = '?'; - } + if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127)) + { + ch = '?'; + } #endif #if 0 - if (p->dca_ptr == 2) { - p->in_dca = 0; - } + if (p->dca_ptr == 2) + { + p->in_dca = 0; + } #endif - if (ch == SYM_CHAR_RESET) { - vt102_reset_state (c); - } else if (p->in_cmd && !ctrl_chr (ch, p->cmd_termination)) { - p->cmd_buf[p->cmd_ptr++] = ch; - if (p->cmd_ptr == VT102_CMD_LEN) - p->in_cmd = 0; - if (p->cmd_more_bytes) { - p->cmd_more_bytes--; + if (ch == SYM_CHAR_RESET) + { + vt102_reset_state (c); + } + else if (p->in_cmd && !ctrl_chr (ch, p->cmd_termination)) + { + p->cmd_buf[p->cmd_ptr++] = ch; + if (p->cmd_ptr == VT102_CMD_LEN) + p->in_cmd = 0; + if (p->cmd_more_bytes) + { + p->cmd_more_bytes--; - if (!p->cmd_more_bytes == 1) - p->in_cmd = 0; + if (!p->cmd_more_bytes == 1) + p->in_cmd = 0; + } + + switch (p->cmd_termination) + { + case 0: + break; + default: + if (p->cmd_termination == ch) + p->in_cmd = 0; + break; + case CSI_ENDER: + if (csi_ender (ch)) + p->in_cmd = 0; + break; + } + + if (!p->in_cmd) + { + vt102_parse_esc (c); + p->cmd_more_bytes = 0; + p->cmd_termination = 0; + } } + else if (p->in_escape && !ctrl_chr (ch, 0)) + { + p->cmd_ptr = 0; + p->cmd_buf[p->cmd_ptr++] = ch; + p->in_escape = 0; - switch (p->cmd_termination) { - case 0: - break; - default: - if (p->cmd_termination == ch) - p->in_cmd = 0; - break; - case CSI_ENDER: - if (csi_ender (ch)) - p->in_cmd = 0; - break; + pre_parse_cmd (ch, p); + + if (!p->in_cmd) + vt102_parse_esc (c); } + else if (ch == 0x9b) + { /*One byte CSI */ + p->cmd_ptr = 0; + p->cmd_buf[p->cmd_ptr++] = '['; - if (!p->in_cmd) { - vt102_parse_esc (c); - p->cmd_more_bytes = 0; - p->cmd_termination = 0; + pre_parse_cmd (ch, p); } - } else if (p->in_escape && !ctrl_chr (ch, 0)) { - p->cmd_ptr = 0; - p->cmd_buf[p->cmd_ptr++] = ch; - p->in_escape = 0; + else + { +#ifdef DEBUG + if (ch != 27) + log_f (c->l, + "pos.x, v->pos.y, v->pending_wrap, ch, ch, safe_ch (ch)); - pre_parse_cmd (ch, p); +#endif - if (!p->in_cmd) - vt102_parse_esc (c); - } else if (ch == 0x9b) { /*One byte CSI */ - p->cmd_ptr = 0; - p->cmd_buf[p->cmd_ptr++] = '['; + switch (ch) + { + /*NUL*/ case 0: + break; +#if 0 + /*SOH*/ case 1: + /*STX*/ case 2: + /*ETX*/ case 3: + /*EOT*/ case 4: + break; +#endif + /*ENQ*/ case 5: + vt102_send_id (c, terminal_id); + break; +#if 0 + /*ACK*/ case 6: + break; +#endif + /*BEL*/ case 7: + //FIXME beep + break; + /*BS*/ case 8: + vt102_cursor_retreat (c->v); + break; + /*HT*/ case 9: + vt102_cursor_advance_tab (c->v); + break; + /*LF*/ case 10: + /*VT*/ case 11: + /*FF*/ case 12: + vt102_cursor_advance_line (c); + if (!v->modes[VT102_MODE_NEWLINE_MODE]) + break; + /*CR*/ case 13: + vt102_cursor_carriage_return (v); + break; + /*SO*/ case 14: + /*select G1 */ + v->cs = 1; + break; + /*SI*/ case 15: + /*select G0 */ + v->cs = 0; + break; +#if 0 + /*DLE*/ case 16: + /*DC1 */ case 17: + /*DC2 */ case 18: + /*DC3 */ case 19: + /*DC4 */ case 20: + /*NAK*/ case 21: + /*SYN*/ case 22: + /*ETB*/ case 23: + /*CAN*/ case 24: + /*EM*/ case 25: + /*SUB*/ case 26: + break; +#endif + /*ESC*/ case 27: + p->in_escape++; + return; +#if 0 + /*FS*/ case 28: + /*GS*/ case 29: + /*RS*/ case 30: + /*US*/ case 31: + /*DEL*/ case 127: + break; +#endif + /*regular character */ default: + vt102_regular_char (c, v, ch); + } - pre_parse_cmd (ch, p); - } else { #ifdef DEBUG - if (ch != 27) - log_f (c->l, - "pos.x, v->pos.y, v->pending_wrap, ch, ch, safe_ch (ch)); + if (ch != 27) + log_f (c->l, "", v->pos.x, v->pos.y, + v->pending_wrap); +#endif + } + vt102_crt_update (c); + + +} + +void +vt102_send (Context * c, uint8_t key) +{ + uint8_t ch; + + if (!c->t) + return; + +#if 0 + fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' '); #endif + if ((key > 31) && (key < 127)) + { + c->t->xmit (c->t, &key, 1); + return; + } - switch (ch) { + switch (key) + { /*NUL*/ case 0: - break; -#if 0 /*SOH*/ case 1: /*STX*/ case 2: /*ETX*/ case 3: /*EOT*/ case 4: - break; -#endif /*ENQ*/ case 5: - vt102_send_id (c, terminal_id); - break; -#if 0 /*ACK*/ case 6: - break; -#endif /*BEL*/ case 7: - //FIXME beep - break; /*BS*/ case 8: - vt102_cursor_retreat (c->v); - break; /*HT*/ case 9: - vt102_cursor_advance_tab (c->v); - break; /*LF*/ case 10: /*VT*/ case 11: /*FF*/ case 12: - vt102_cursor_advance_line (c); - if (!v->modes[VT102_MODE_NEWLINE_MODE]) - break; + c->t->xmit (c->t, &key, 1); + break; /*CR*/ case 13: - vt102_cursor_carriage_return (v); + c->t->xmit (c->t, &key, 1); + if (c->v->modes[VT102_MODE_NEWLINE_MODE]) + { + ch = 10; + c->t->xmit (c->t, &ch, 1); + } break; /*SO*/ case 14: - /*select G1 */ - v->cs = 1; - break; /*SI*/ case 15: - /*select G0 */ - v->cs = 0; - break; -#if 0 /*DLE*/ case 16: /*DC1 */ case 17: /*DC2 */ case 18: @@ -1764,187 +1940,116 @@ vt102_parse_char (Context * c, int ch) /*CAN*/ case 24: /*EM*/ case 25: /*SUB*/ case 26: + c->t->xmit (c->t, &key, 1); break; -#endif /*ESC*/ case 27: - p->in_escape++; - return; -#if 0 /*FS*/ case 28: /*GS*/ case 29: /*RS*/ case 30: /*US*/ case 31: /*DEL*/ case 127: + c->t->xmit (c->t, &key, 1); break; -#endif - /*regular character */ default: - vt102_regular_char (c, v, ch); - } - -#ifdef DEBUG - if (ch != 27) - log_f (c->l, "", v->pos.x, v->pos.y, - v->pending_wrap); -#endif - } - vt102_crt_update (c); - - -} - -void -vt102_send (Context * c, uint8_t key) -{ - uint8_t ch; + case KEY_UP: + case KEY_DOWN: + case KEY_RIGHT: + case KEY_LEFT: + case KEY_HOME: + case KEY_MIDDLE: + case KEY_END: - if (!c->t) - return; - -#if 0 - fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' '); -#endif - if ((key > 31) && (key < 127)) { - c->t->xmit (c->t, &key, 1); - return; - } - - switch (key) { - /*NUL*/ case 0: - /*SOH*/ case 1: - /*STX*/ case 2: - /*ETX*/ case 3: - /*EOT*/ case 4: - /*ENQ*/ case 5: - /*ACK*/ case 6: - /*BEL*/ case 7: - /*BS*/ case 8: - /*HT*/ case 9: - /*LF*/ case 10: - /*VT*/ case 11: - /*FF*/ case 12: - c->t->xmit (c->t, &key, 1); - break; - /*CR*/ case 13: - c->t->xmit (c->t, &key, 1); - if (c->v->modes[VT102_MODE_NEWLINE_MODE]) { - ch = 10; - c->t->xmit (c->t, &ch, 1); - } - break; - /*SO*/ case 14: - /*SI*/ case 15: - /*DLE*/ case 16: - /*DC1 */ case 17: - /*DC2 */ case 18: - /*DC3 */ case 19: - /*DC4 */ case 20: - /*NAK*/ case 21: - /*SYN*/ case 22: - /*ETB*/ case 23: - /*CAN*/ case 24: - /*EM*/ case 25: - /*SUB*/ case 26: - c->t->xmit (c->t, &key, 1); - break; - /*ESC*/ case 27: - /*FS*/ case 28: - /*GS*/ case 29: - /*RS*/ case 30: - /*US*/ case 31: - /*DEL*/ case 127: - c->t->xmit (c->t, &key, 1); - break; - - case KEY_UP: - case KEY_DOWN: - case KEY_RIGHT: - case KEY_LEFT: - case KEY_HOME: - case KEY_MIDDLE: - case KEY_END: - - if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE]) { - uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } else { - uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - break; - case KEY_STAR: - case KEY_PLUS: - case KEY_COMMA: - case KEY_PERIOD: - case KEY_DIVIDE: - case KEY_0: - case KEY_1: - case KEY_2: - case KEY_3: - case KEY_4: - case KEY_5: - case KEY_6: - case KEY_7: - case KEY_8: - case KEY_9: - if (c->v->application_keypad_mode) { - uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } else { - static char kpoff[KEY_NUM] = { - [KEY_STAR] = '*', - [KEY_PLUS] = '+', - [KEY_COMMA] = ',', - [KEY_MINUS] = '-', - [KEY_PERIOD] = '.', - [KEY_DIVIDE] = '/', - [KEY_0] = '0', - [KEY_1] = '1', - [KEY_2] = '2', - [KEY_3] = '3', - [KEY_4] = '4', - [KEY_5] = '5', - [KEY_6] = '6', - [KEY_7] = '7', - [KEY_8] = '8', - [KEY_9] = '9' - }; - - c->t->xmit (c->t, &kpoff[key], 1); - } - break; - case KEY_ENTER: - if (c->v->application_keypad_mode) { - uint8_t buf[] = { 033, 'O', 'M' }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } else { - ch = 13; - c->t->xmit (c->t, &ch, 1); - if (c->v->modes[VT102_MODE_NEWLINE_MODE]) { - ch = 10; - c->t->xmit (c->t, &ch, 1); + if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE]) + { + uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } + else + { + uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } + break; + case KEY_STAR: + case KEY_PLUS: + case KEY_COMMA: + case KEY_PERIOD: + case KEY_DIVIDE: + case KEY_0: + case KEY_1: + case KEY_2: + case KEY_3: + case KEY_4: + case KEY_5: + case KEY_6: + case KEY_7: + case KEY_8: + case KEY_9: + if (c->v->application_keypad_mode) + { + uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } + else + { + static char kpoff[KEY_NUM] = { + [KEY_STAR] = '*', + [KEY_PLUS] = '+', + [KEY_COMMA] = ',', + [KEY_MINUS] = '-', + [KEY_PERIOD] = '.', + [KEY_DIVIDE] = '/', + [KEY_0] = '0', + [KEY_1] = '1', + [KEY_2] = '2', + [KEY_3] = '3', + [KEY_4] = '4', + [KEY_5] = '5', + [KEY_6] = '6', + [KEY_7] = '7', + [KEY_8] = '8', + [KEY_9] = '9' + }; + + c->t->xmit (c->t, &kpoff[key], 1); + } + break; + case KEY_ENTER: + if (c->v->application_keypad_mode) + { + uint8_t buf[] = { 033, 'O', 'M' }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } + else + { + ch = 13; + c->t->xmit (c->t, &ch, 1); + if (c->v->modes[VT102_MODE_NEWLINE_MODE]) + { + ch = 10; + c->t->xmit (c->t, &ch, 1); + } + } + break; + case KEY_PF1: + case KEY_PF2: + case KEY_PF3: + case KEY_PF4: + { + uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) }; + c->t->xmit (c->t, &buf, sizeof (buf)); } + break; + case KEY_INSERT: + case KEY_DELETE: + case KEY_PGUP: + case KEY_PGDN: + { + uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } + break; } - break; - case KEY_PF1: - case KEY_PF2: - case KEY_PF3: - case KEY_PF4: - { - uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - break; - case KEY_INSERT: - case KEY_DELETE: - case KEY_PGUP: - case KEY_PGDN: - { - uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - break; - } } @@ -1992,23 +2097,26 @@ vt102_new (CRT_Pos * size) v->xn_glitch = 1; - if (size) { - v->original_size = *size; + if (size) + { + v->original_size = *size; - if (v->original_size.x < 1) - v->original_size.x = 1; - if (v->original_size.y < 1) - v->original_size.y = 1; + if (v->original_size.x < 1) + v->original_size.x = 1; + if (v->original_size.y < 1) + v->original_size.y = 1; - if (v->original_size.x > VT102_MAX_COLS) - v->original_size.x = VT102_MAX_COLS; - if (v->original_size.y > VT102_MAX_ROWS) - v->original_size.y = VT102_MAX_ROWS; + if (v->original_size.x > VT102_MAX_COLS) + v->original_size.x = VT102_MAX_COLS; + if (v->original_size.y > VT102_MAX_ROWS) + v->original_size.y = VT102_MAX_ROWS; - } else { - v->original_size.x = VT102_COLS_80; - v->original_size.y = VT102_ROWS_24; - } + } + else + { + v->original_size.x = VT102_COLS_80; + v->original_size.y = VT102_ROWS_24; + } return v; } diff --git a/src/vt102.h b/src/vt102.h index 428abfc..f475b9f 100644 --- a/src/vt102.h +++ b/src/vt102.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.23 2008/03/03 06:04:42 james + * *** empty log message *** + * * Revision 1.22 2008/03/02 10:37:56 james * *** empty log message *** * @@ -95,7 +98,8 @@ #define VT102_NMODES 32 -typedef struct { +typedef struct +{ int in_escape; int in_cmd; @@ -105,7 +109,8 @@ typedef struct { char cmd_buf[VT102_CMD_LEN]; } VT102_parser; -typedef struct { +typedef struct +{ CRT_Pos pos; int attr; int color; @@ -113,7 +118,8 @@ typedef struct { } VT102_State; -typedef struct { +typedef struct +{ CRT_Pos top_margin, bottom_margin; CRT_Pos screen_start, screen_end; VT102_parser parser; diff --git a/sympathy.1 b/sympathy.1 index 7a7e436..f85ea8e 100644 --- a/sympathy.1 +++ b/sympathy.1 @@ -177,8 +177,22 @@ turn on flow control on the terminal device. This option adds \fICRTSCTS\fP to s \fIc_cflag\fPs of \fICS8|CREAD|CLOCAL\fP. .TP 5 .B \-L \fIlogfile\fP -log activity to the file \fIlogfile\fP. If \fIlogfile\fP is `-' then log to \fIstdout\fP. Note -that logging to \fIstdout\fP only makes sense with the \-\fBF\fP \fIserver_option\fP. +log activity to the file \fIlogfile\fP. If \fIlogfile\fP is `-' then log to +\fIstdout\fP. Note that logging to \fIstdout\fP only makes sense with the +\-\fBF\fP \fIserver_option\fP. +.TP 5 +.B \-P \fIpidfile\fP +write the pid of the server/terminal process to \fIpidfile\fP, which is +removed on clean exit. +.TP 5 +.B \-R +rotate log files. When the logfile specified with the \fB\-L\fI option +grows large +.I sympathy +will rotate it and compress old logfiles. +.I Sympathy +will also close and reopen its log file when it receives a \fBSIGHUP\fP which +with the \fB\-P\fP allows the use of logrotate(8). .TP 5 .B \-w \fIwidth\fP[x\fIheight\fP] set the initial size of the terminal emulator's frame buffer to be \fIwidth\fP columns @@ -312,7 +326,9 @@ Commands are entered by sending the escape character, ascii(7) STX, from the out emulator (usually by pressing CTRL\-B), typing the command and pressing return. Whilst the command is entered the status line changes to `:' and rudimentary line editing is available. Whilst the command is entered the cursor \fBdoes not move\fP but remains where the terminal -emulator has placed it. Valid commands are: +emulator has placed it. Pressing the escape character whilst in command mode +will send the escape character to the terminal and cancel command mode. Valid +commands are: .TP 7 .B ansi switch from VT102 behaviour to ANSI behaviour. The most noticeable difference is @@ -398,6 +414,34 @@ and the conclusions of the baud\-rate guessing algorithm Invalid UTF\-8 sequences are also reported .IP +.PP +The log file is rotate when it gets too large if the \fI\-R\fP option +is specified, and the log file is re-opened on recipt of a \fBSIGHUP\fP +which together with the \fB\-P\fP allows the use of of a program such +as logrotate(8) +.SH SIGNALS +.I Sympathy +reacts to a set of signals. You can use the \fB-P\fI option +to easily determine the PID of the +.I sympathy +process to which you would like to send a signal. +.TP 8 +.B SIGINT +.I Sympathy +will immediately try to restore the outer terminal emulator to its original +state and then exit. +.TP 8 +.B SIGHUP +.I Sympathy +will close and reopen the log-file specified with the -L option, which allows +the use of programs like logrotate(8) +.B SIGWINCH +.I Sympathy +will redraw the display in the outer terminal emulator so that it will fit within +the new display size. +SIGCHLD +.I Sympathy +will wait for children if some were born (for example from compressing rotated logs) .SH ENVIRONMENT .I sympathy uses the \fBHOME\fP environment variable to determine the default diff --git a/version-files b/version-files index 51f20da..c9b3fd7 100644 --- a/version-files +++ b/version-files @@ -32,6 +32,7 @@ src/ptty.c src/render.c src/ring.c src/ring.h +src/rotate.c src/serial.c src/slide.c src/slide.h -- cgit v1.2.3