chiark / gitweb /
820f4d9703b986d220f20773f8e8b369f649624f
[sympathy.git] / apps / sympathyd.c
1 /*
2  * sympathy.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.4  2008/02/13 17:21:55  james
14  * *** empty log message ***
15  *
16  * Revision 1.3  2008/02/08 15:06:52  james
17  * *** empty log message ***
18  *
19  * Revision 1.2  2008/02/07 15:42:49  james
20  * *** empty log message ***
21  *
22  * Revision 1.1  2008/02/05 14:25:49  james
23  * *** empty log message ***
24  *
25  */
26
27 #include "sympathy.h"
28
29 #include 
30 void main (int argc,char *argv[])
31 {
32   fd_set rfd, wfd;
33   ANSI a = { 0 };
34   Context c;
35   Socket *s, *cs;
36   Client **clients;
37
38
39   s = socket_listen ("socket");
40
41   c.t = ptty_open (NULL, NULL);
42   c.v = vt102_new ();
43   c.h = history_new (200);
44   c.l = file_log_new ("log");
45
46   terminal_register_handlers ();
47   a.terminal = terminal_open (0, 1);
48
49   ansi_reset (&a, NULL);
50
51   clients=clients_new();
52
53   for (;;)
54     {
55       struct timeval tv = { 0, 100000 };
56
57
58       FD_ZERO (&rfd);
59       FD_ZERO (&wfd);
60
61       tty_pre_select (c.t, &rfd);
62       tty_pre_select (a.terminal, &rfd);
63
64       socket_pre_select (s, &rfd, &wfd);
65
66       client_pre_select (clients);
67
68       select (FD_SETSIZE, &rfd, NULL, NULL, &tv);
69
70       cs = socket_post_select (s, &rfd, &wfd);
71
72       if (cs)
73         {
74           /*New client connexion */
75           clients_new (clients, cs, c);
76         }
77
78       clients_post_select (clients, c, &rfds, &wfds);
79
80       if (FD_ISSET (c->t->rfd, &rfds))
81         {
82           char buf[1024];
83           int red;
84
85           red = c->t->recv (c->t, buf, sizeof (buf));
86
87           if (red < 0)
88             break;
89
90           if (red)
91             {
92               clients_output (clients, buf, red);
93               vt102_parse (c, buf, red);
94             }
95         }
96
97       ansi_dispatch (&a, &c);
98       ansi_update (&a, &c);
99     }
100
101   clients_shutdown (clients);
102   ansi_terminal_reset (&a);
103   terminal_atexit ();
104   printf ("QUAT\n");
105 }