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.8 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>
17 #include <bitstring.h>
23 #include "../common/common.h"
28 * Construct and send an IP buffer.
30 * PUBLIC: int vi_send __P((char *, IP_BUF *));
45 * Have not created the channel to vi yet? -- RAZ
48 * How is that possible!?!?
53 if (blen
== 0 && (bp
= malloc(blen
= 512)) == NULL
)
62 for (; *fmt
!= '\0'; ++fmt
)
64 case '1': /* Value #1. */
65 ilen
= htonl(ipbp
->val1
);
67 case '2': /* Value #2. */
68 ilen
= htonl(ipbp
->val2
);
70 case '3': /* Value #3. */
71 ilen
= htonl(ipbp
->val3
);
72 value
: nlen
+= IPO_INT_LEN
;
74 blen
= blen
* 2 + nlen
;
76 if ((bp
= realloc(bp
, blen
)) == NULL
)
80 memcpy(p
, &ilen
, IPO_INT_LEN
);
83 case 'a': /* String #1. */
84 case 'b': /* String #2. */
85 ilen
= *fmt
== 'a' ? ipbp
->len1
: ipbp
->len2
;
86 nlen
+= IPO_INT_LEN
+ ilen
;
88 blen
= blen
* 2 + nlen
;
90 if ((bp
= realloc(bp
, blen
)) == NULL
)
95 memcpy(p
, &ilen
, IPO_INT_LEN
);
98 memcpy(p
, ipbp
->str1
, ipbp
->len1
);
101 memcpy(p
, ipbp
->str2
, ipbp
->len2
);
106 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
107 if ((nw
= write(vi_ofd
, p
, n
)) < 0)