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