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.15 1997/08/02 16:49:33 bostic Exp $ (Berkeley) $Date: 1997/08/02 16:49:33 $";
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((int));
48 /* Read waiting vi messages and translate to X calls. */
49 switch (nr
= read(fd
, ibuf
+ ibuf_len
, sizeof(ibuf
) - ibuf_len
)) {
59 /* Parse to data end or partial message. */
60 (void)vi_translate(ibuf
, &ibuf_len
, NULL
);
62 return (ibuf_len
> 0);
67 * Construct and send an IP buffer, and wait for an answer.
69 * PUBLIC: int vi_wsend __P((char *, IP_BUF *));
79 if (vi_send(fmt
, ipbp
))
83 ipbp
->code
= CODE_OOB
;
86 FD_SET(vi_ifd
, &rdfd
);
87 if (select(vi_ifd
+ 1, &rdfd
, NULL
, NULL
, NULL
) != 0)
90 /* Read waiting vi messages and translate to X calls. */
92 read(vi_ifd
, ibuf
+ ibuf_len
, sizeof(ibuf
) - ibuf_len
)) {
102 /* Parse to data end or partial message. */
103 (void)vi_translate(ibuf
, &ibuf_len
, ipbp
);
105 if (ipbp
->code
!= CODE_OOB
)
113 * Translate vi messages into function calls.
115 * PUBLIC: int vi_translate __P((char *, size_t *, IP_BUF *));
118 vi_translate(bp
, lenp
, ipbp
)
123 extern int (*__vi_iplist
[SI_EVENT_MAX
- 1]) __P((IP_BUF
*));
127 char *fmt
, *p
, *s_bp
, **vsp
;
129 for (s_bp
= bp
, len
= *lenp
; len
> 0;) {
130 switch (ipb
.code
= bp
[0]) {
157 p
= bp
+ IPO_CODE_LEN
;
158 needlen
= IPO_CODE_LEN
;
159 for (; *fmt
!= '\0'; ++fmt
)
161 case '1': /* Value #1. */
164 case '2': /* Value #2. */
167 case '3': /* Value #3. */
169 value
: needlen
+= IPO_INT_LEN
;
172 memcpy(vp
, p
, IPO_INT_LEN
);
176 case 'a': /* String #1. */
180 case 'b': /* String #2. */
183 string
: needlen
+= IPO_INT_LEN
;
186 memcpy(vp
, p
, IPO_INT_LEN
);
203 if (ipb
.code
> SI_EVENT_MAX
) {
209 * If we're waiting for a reply and we got it, return it, and
210 * leave any unprocessed data in the buffer. If we got a reply
211 * and we're not waiting for one, discard it -- callers wait
214 if (ipb
.code
== SI_REPLY
) {
221 /* Call the underlying routine. */
222 if (__vi_iplist
[ipb
.code
- 1](&ipb
))
226 if ((*lenp
= len
) != 0)
227 memmove(s_bp
, bp
, len
);