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