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