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.6 1996/12/17 10:45:15 bostic Exp $ (Berkeley) $Date: 1996/12/17 10:45:15 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
17 #include <bitstring.h>
23 #include "../common/common.h"
25 #include "ipc_extern.h"
27 extern int vi_ofd
; /* Output file descriptor. */
31 * Construct and send an IP buffer.
33 * PUBLIC: int __vi_send __P((char *, IP_BUF *));
48 * Have not created the channel to vi yet? -- RAZ
51 * How is that possible!?!?
56 if (blen
== 0 && (bp
= malloc(blen
= 512)) == NULL
)
65 for (; *fmt
!= '\0'; ++fmt
)
67 case '1': /* Value #1. */
68 ilen
= htonl(ipbp
->val1
);
70 case '2': /* Value #2. */
71 ilen
= htonl(ipbp
->val2
);
73 case '3': /* Value #3. */
74 ilen
= htonl(ipbp
->val3
);
75 value
: nlen
+= IPO_INT_LEN
;
77 blen
= blen
* 2 + nlen
;
79 if ((bp
= realloc(bp
, blen
)) == NULL
)
83 memcpy(p
, &ilen
, IPO_INT_LEN
);
86 case 'a': /* String #1. */
87 case 'b': /* String #2. */
88 ilen
= *fmt
== 'a' ? ipbp
->len1
: ipbp
->len2
;
89 nlen
+= IPO_INT_LEN
+ ilen
;
91 blen
= blen
* 2 + nlen
;
93 if ((bp
= realloc(bp
, blen
)) == NULL
)
98 memcpy(p
, &ilen
, IPO_INT_LEN
);
101 memcpy(p
, ipbp
->str1
, ipbp
->len1
);
104 memcpy(p
, ipbp
->str2
, ipbp
->len2
);
109 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
110 if ((nw
= write(vi_ofd
, p
, n
)) < 0)