/* * sympathy.c: * * Copyright (c) 2008 James McKenzie , * All rights reserved. * */ static char rcsid[] = "$Id$"; /* * $Log$ * Revision 1.7 2008/02/14 02:46:44 james * *** empty log message *** * * Revision 1.6 2008/02/14 00:57:58 james * *** empty log message *** * * Revision 1.5 2008/02/13 18:05:06 james * *** empty log message *** * * Revision 1.4 2008/02/13 17:21:55 james * *** empty log message *** * * Revision 1.3 2008/02/08 15:06:52 james * *** empty log message *** * * Revision 1.2 2008/02/07 15:42:49 james * *** empty log message *** * * Revision 1.1 2008/02/05 14:25:49 james * *** empty log message *** * */ #include #include "client.h" #include "clients.h" static void send_history (History * h, Client * c) { int rptr = h->wptr; HISTORY_INC (h, rptr); HISTORY_INC (h, rptr); while (rptr != h->wptr) { History_ent *l = &h->lines[rptr]; if (l->valid) { if (ipc_msg_send_history (c->s, l)) c->dead++; } HISTORY_INC (h, rptr); } } static void send_vt102 (VT102 * v, Client * c) { if (ipc_msg_send_vt102 (c->s, v)) c->dead++; } int main (int argc, char *argv[]) { fd_set rfds, wfds; // ANSI a = { 0 }; Context c; Socket *s, *cs; Clients *clients; s = socket_listen ("socket"); c.t = ptty_open (NULL, NULL); c.v = vt102_new (); c.h = history_new (200); c.l = file_log_new ("log"); c.k = keydis_vt102_new (&c); #if 0 terminal_register_handlers (); a.terminal = terminal_open (0, 1); ansi_reset (&a, NULL); #endif clients = clients_new (); for (;;) { struct timeval tv = { 10, 0 }; FD_ZERO (&rfds); FD_ZERO (&wfds); tty_pre_select (c.t, &rfds, &wfds); #if 0 tty_pre_select (a.terminal, &rfds, &wfds); #endif FD_SET (s->fd, &rfds); socket_pre_select (s, &rfds, &wfds); clients_pre_select (clients, &rfds, &wfds); select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); if (FD_ISSET (s->fd, &rfds) && ((cs = socket_accept (s)))) { { Client *cl; /*New client connexion */ cl = clients_new_client (clients, cs, &c); send_history (c.h, cl); send_vt102 (c.v, cl); } } clients_post_select (clients, &c, &rfds, &wfds); if (FD_ISSET (c.t->rfd, &rfds)) { char buf[IPC_MAX_BUF]; int red; red = c.t->recv (c.t, buf, sizeof (buf)); if (red < 0) break; if (red) { clients_output (clients, buf, red); vt102_parse (&c, buf, red); } } #if 0 ansi_dispatch (&a, &c); ansi_update (&a, &c); #endif } clients_shutdown (clients); #if 0 ansi_terminal_reset (&a); #endif terminal_atexit (); printf ("QUAT\n"); }