3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "$Id: ip_trans.c,v 8.16 2000/06/28 20:20:39 skimo Exp $ (Berkeley) $Date: 2000/06/28 20:20:39 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
16 #ifdef HAVE_SYS_SELECT_H
17 #include <sys/select.h>
20 #include <bitstring.h>
30 #include "../common/common.h"
33 static char ibuf
[2048]; /* Input buffer. */
34 static size_t ibuf_len
; /* Length of current input. */
38 * Read from the vi message queue.
40 * PUBLIC: int vi_input __P((IPVIWIN *, int));
49 /* Read waiting vi messages and translate to X calls. */
50 switch (nr
= read(fd
, ibuf
+ ibuf_len
, sizeof(ibuf
) - ibuf_len
)) {
60 /* Parse to data end or partial message. */
61 (void)vi_translate(ipviwin
, ibuf
, &ibuf_len
, NULL
);
63 return (ibuf_len
> 0);
68 * Construct and send an IP buffer, and wait for an answer.
70 * PUBLIC: int vi_wsend __P((IPVIWIN*, char *, IP_BUF *));
73 vi_wsend(ipviwin
, fmt
, ipbp
)
81 if (vi_send(ipviwin
->ofd
, fmt
, ipbp
))
85 ipbp
->code
= CODE_OOB
;
88 FD_SET(ipviwin
->ifd
, &rdfd
);
89 if (select(ipviwin
->ifd
+ 1, &rdfd
, NULL
, NULL
, NULL
) != 0)
92 /* Read waiting vi messages and translate to X calls. */
94 read(ipviwin
->ifd
, ibuf
+ ibuf_len
, sizeof(ibuf
) - ibuf_len
)) {
104 /* Parse to data end or partial message. */
105 (void)vi_translate(ipviwin
, ibuf
, &ibuf_len
, ipbp
);
107 if (ipbp
->code
!= CODE_OOB
)
115 * Translate vi messages into function calls.
117 * PUBLIC: int vi_translate __P((IPVIWIN *, char *, size_t *, IP_BUF *));
120 vi_translate(ipviwin
, bp
, lenp
, ipbp
)
126 extern int (*__vi_iplist
[SI_EVENT_MAX
- 1]) __P((IP_BUF
*));
130 char *fmt
, *p
, *s_bp
;
133 for (s_bp
= bp
, len
= *lenp
; len
> 0;) {
134 switch (ipb
.code
= bp
[0]) {
161 p
= bp
+ IPO_CODE_LEN
;
162 needlen
= IPO_CODE_LEN
;
163 for (; *fmt
!= '\0'; ++fmt
)
165 case '1': /* Value #1. */
168 case '2': /* Value #2. */
171 case '3': /* Value #3. */
173 value
: needlen
+= IPO_INT_LEN
;
176 memcpy(vp
, p
, IPO_INT_LEN
);
180 case 'a': /* String #1. */
184 case 'b': /* String #2. */
187 string
: needlen
+= IPO_INT_LEN
;
190 memcpy(vp
, p
, IPO_INT_LEN
);
207 if (ipb
.code
> SI_EVENT_MAX
) {
213 * If we're waiting for a reply and we got it, return it, and
214 * leave any unprocessed data in the buffer. If we got a reply
215 * and we're not waiting for one, discard it -- callers wait
218 if (ipb
.code
== SI_REPLY
) {
225 /* Call the underlying routine. */
226 if (__vi_iplist
[ipb
.code
- 1](&ipb
))
230 if ((*lenp
= len
) != 0)
231 memmove(s_bp
, bp
, len
);