5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "Id: ip_send.c,v 8.10 2001/06/25 15:19:25 skimo Exp (Berkeley) Date: 2001/06/25 15:19:25";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
25 #include "../common/common.h"
30 * Construct and send an IP buffer.
32 * PUBLIC: int vi_send __P((int, char *, IP_BUF *));
35 vi_send(int ofd
, char *fmt
, IP_BUF
*ipbp
)
45 * Have not created the channel to vi yet? -- RAZ
48 * How is that possible!?!?
50 * We'll soon find out.
53 fprintf(stderr
, "No channel\n");
57 if (blen
== 0 && (bp
= malloc(blen
= 512)) == NULL
)
66 for (; *fmt
!= '\0'; ++fmt
)
68 case '1': /* Value #1. */
69 ilen
= htonl(ipbp
->val1
);
71 case '2': /* Value #2. */
72 ilen
= htonl(ipbp
->val2
);
74 case '3': /* Value #3. */
75 ilen
= htonl(ipbp
->val3
);
76 value
: nlen
+= IPO_INT_LEN
;
78 blen
= blen
* 2 + nlen
;
80 if ((bp
= realloc(bp
, blen
)) == NULL
)
84 memcpy(p
, &ilen
, IPO_INT_LEN
);
87 case 'a': /* String #1. */
88 case 'b': /* String #2. */
89 ilen
= *fmt
== 'a' ? ipbp
->len1
: ipbp
->len2
;
90 nlen
+= IPO_INT_LEN
+ ilen
;
92 blen
= blen
* 2 + nlen
;
94 if ((bp
= realloc(bp
, blen
)) == NULL
)
99 memcpy(p
, &ilen
, IPO_INT_LEN
);
102 memcpy(p
, ipbp
->str1
, ipbp
->len1
);
105 memcpy(p
, ipbp
->str2
, ipbp
->len2
);
110 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
111 if ((nw
= write(ofd
, p
, n
)) < 0)