3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "$Id: ip_send.c,v 8.9 2000/06/28 20:20:38 skimo Exp $ (Berkeley) $Date: 2000/06/28 20:20:38 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
17 #include <bitstring.h>
23 #include "../common/common.h"
28 * Construct and send an IP buffer.
30 * PUBLIC: int vi_send __P((int, char *, IP_BUF *));
33 vi_send(ofd
, fmt
, ipbp
)
46 * Have not created the channel to vi yet? -- RAZ
49 * How is that possible!?!?
51 * We'll soon find out.
54 fprintf(stderr
, "No channel\n");
58 if (blen
== 0 && (bp
= malloc(blen
= 512)) == NULL
)
67 for (; *fmt
!= '\0'; ++fmt
)
69 case '1': /* Value #1. */
70 ilen
= htonl(ipbp
->val1
);
72 case '2': /* Value #2. */
73 ilen
= htonl(ipbp
->val2
);
75 case '3': /* Value #3. */
76 ilen
= htonl(ipbp
->val3
);
77 value
: nlen
+= IPO_INT_LEN
;
79 blen
= blen
* 2 + nlen
;
81 if ((bp
= realloc(bp
, blen
)) == NULL
)
85 memcpy(p
, &ilen
, IPO_INT_LEN
);
88 case 'a': /* String #1. */
89 case 'b': /* String #2. */
90 ilen
= *fmt
== 'a' ? ipbp
->len1
: ipbp
->len2
;
91 nlen
+= IPO_INT_LEN
+ ilen
;
93 blen
= blen
* 2 + nlen
;
95 if ((bp
= realloc(bp
, blen
)) == NULL
)
100 memcpy(p
, &ilen
, IPO_INT_LEN
);
103 memcpy(p
, ipbp
->str1
, ipbp
->len1
);
106 memcpy(p
, ipbp
->str2
, ipbp
->len2
);
111 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
112 if ((nw
= write(ofd
, p
, n
)) < 0)