chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / tty.c
1 /*
2  * tty.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.8  2008/02/14 10:36:18  james
14  * *** empty log message ***
15  *
16  * Revision 1.7  2008/02/14 10:34:30  james
17  * *** empty log message ***
18  *
19  * Revision 1.6  2008/02/13 16:59:34  james
20  * *** empty log message ***
21  *
22  * Revision 1.5  2008/02/13 16:57:29  james
23  * *** empty log message ***
24  *
25  * Revision 1.4  2008/02/12 22:36:46  james
26  * *** empty log message ***
27  *
28  * Revision 1.3  2008/02/09 15:47:28  james
29  * *** empty log message ***
30  *
31  */
32
33
34 #include "project.h"
35
36 static int
37 speed_t_to_baud (speed_t s)
38 {
39   switch (s)
40     {
41 #ifdef B0
42     case B0:
43       return 0;
44 #endif
45 #ifdef B50
46     case B50:
47       return 50;
48 #endif
49 #ifdef B75
50     case B75:
51       return 75;
52 #endif
53 #ifdef B110
54     case B110:
55       return 110;
56 #endif
57 #ifdef B134
58     case B134:
59       return 134;
60 #endif
61 #ifdef B150
62     case B150:
63       return 150;
64 #endif
65 #ifdef B200
66     case B200:
67       return 200;
68 #endif
69 #ifdef B300
70     case B300:
71       return 300;
72 #endif
73 #ifdef B600
74     case B600:
75       return 600;
76 #endif
77 #ifdef B1200
78     case B1200:
79       return 1200;
80 #endif
81 #ifdef B1800
82     case B1800:
83       return 1800;
84 #endif
85 #ifdef B2400
86     case B2400:
87       return 2400;
88 #endif
89 #ifdef B4800
90     case B4800:
91       return 4800;
92 #endif
93 #ifdef B9600
94     case B9600:
95       return 9600;
96 #endif
97 #ifdef B19200
98     case B19200:
99       return 19200;
100 #endif
101 #ifdef B38400
102     case B38400:
103       return 38400;
104 #endif
105 #ifdef B57600
106     case B57600:
107       return 57600;
108 #endif
109 #ifdef B115200
110     case B115200:
111       return 115200;
112 #endif
113 #ifdef B230400
114     case B230400:
115       return 230400;
116 #endif
117     }
118
119   return -1;
120 }
121
122 static speed_t
123 baud_to_speed_t (int baud)
124 {
125   switch (baud)
126     {
127 #ifdef B0
128     case 0:
129       return B0;
130 #endif
131 #ifdef B50
132     case 50:
133       return B50;
134 #endif
135 #ifdef B75
136     case 75:
137       return B75;
138 #endif
139 #ifdef B110
140     case 110:
141       return B110;
142 #endif
143 #ifdef B134
144     case 134:
145       return B134;
146 #endif
147 #ifdef B150
148     case 150:
149       return B150;
150 #endif
151 #ifdef B200
152     case 200:
153       return B200;
154 #endif
155 #ifdef B300
156     case 300:
157       return B300;
158 #endif
159 #ifdef B600
160     case 600:
161       return B600;
162 #endif
163 #ifdef B1200
164     case 1200:
165       return B1200;
166 #endif
167 #ifdef B1800
168     case 1800:
169       return B1800;
170 #endif
171 #ifdef B2400
172     case 2400:
173       return B2400;
174 #endif
175 #ifdef B4800
176     case 4800:
177       return B4800;
178 #endif
179 #ifdef B9600
180     case 9600:
181       return B9600;
182 #endif
183 #ifdef B19200
184     case 19200:
185       return B19200;
186 #endif
187 #ifdef B38400
188     case 38400:
189       return B38400;
190 #endif
191 #ifdef B57600
192     case 57600:
193       return B57600;
194 #endif
195 #ifdef B115200
196     case 115200:
197       return B115200;
198 #endif
199 #ifdef B230400
200     case 230400:
201       return B230400;
202 #endif
203     }
204   return -1;
205 }
206
207 void
208 tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds)
209 {
210   FD_SET (t->rfd, rfds);
211 }
212
213 int
214 tty_get_status (TTY * t, TTY_Status * s)
215 {
216
217   s->lines = 0;
218   ioctl (t->rfd, TIOCMGET, &s->lines);
219
220   if (tcgetattr (t->rfd, &s->termios))
221     return -1;
222
223   s->baud = speed_t_to_baud (cfgetispeed (&s->termios));
224   s->blocked = t->blocked;
225
226   return 0;
227 }
228
229 #if 0
230 int
231 tty_post_select (Context * c, fd_set * rfds, fd_set * wfds)
232 {
233
234   if (FD_ISSET (c->t->rfd, rfds))
235     {
236       if (vt102_dispatch (&c))
237         return -1;
238     }
239   return 0;
240 }
241
242 #endif