chiark / gitweb /
90bcf609bd2528e7000db6295082d92137b9eca6
[sympathy.git] / apps / client.c
1 /*
2  * client.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.3  2008/02/14 02:46:44  james
14  * *** empty log message ***
15  *
16  * Revision 1.2  2008/02/14 00:57:58  james
17  * *** empty log message ***
18  *
19  * Revision 1.1  2008/02/13 18:05:06  james
20  * *** empty log message ***
21  *
22  */
23
24 #include <sympathy.h>
25 #include "client.h"
26
27 static void
28 server_msg (IPC_Msg * m, Context * c)
29 {
30   switch (m->hdr.type)
31     {
32
33     case IPC_MSG_TYPE_NOOP:
34       break;
35     case IPC_MSG_TYPE_DEBUG:
36 //          fprintf (stderr,"%p [%d] %s\n", m, m->hdr.size , m->debug.msg );
37       break;
38     case IPC_MSG_TYPE_HISTORY:
39       history_add (c->h, m->history.history.line);
40       break;
41     case IPC_MSG_TYPE_VT102:
42       if (sizeof (VT102) != m->vt102.len)
43         abort ();
44
45       *(c->v) = m->vt102.vt102;
46       break;
47     case IPC_MSG_TYPE_TERM:
48       vt102_parse (c, m->term.term, m->term.len);
49       break;
50     default:
51       fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
52     }
53 }
54
55 void
56 client (void)
57 {
58   Socket *s;
59   fd_set rfds, wfds;
60
61   ANSI a = { 0 };
62   Context c;
63
64   s = socket_connect ("socket");
65
66   if (!s)
67     {
68       printf ("no socket");
69       return;
70     }
71
72   c.t = NULL;
73   c.v = vt102_new ();
74   c.h = history_new (200);
75   c.l = NULL;
76   c.k = keydis_ipc_new (s);
77
78   terminal_register_handlers ();
79   a.terminal = terminal_open (0, 1);
80
81   ansi_reset (&a, NULL);
82
83   for (;;)
84     {
85       struct timeval tv = { 0, 100000 };
86
87       FD_ZERO (&rfds);
88       FD_ZERO (&wfds);
89
90       socket_pre_select (s, &rfds, &wfds);
91       tty_pre_select (a.terminal, &rfds, &wfds);
92
93       select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
94
95       if (socket_post_select (s, &rfds, &wfds))
96         break;
97
98       while (s->msg)
99         {
100           server_msg (s->msg, &c);
101           socket_consume_msg (s);
102         }
103
104       if (ansi_dispatch (&a, &c))
105         break;
106
107       ansi_update (&a, &c);
108
109     }
110   ansi_terminal_reset (&a);
111   terminal_atexit ();
112   printf ("QUAT\n");
113
114
115 }