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