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.10 2001/06/25 15:19:25 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:25 $";
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(int ofd
, char *fmt
, IP_BUF
*ipbp
)
43 * Have not created the channel to vi yet? -- RAZ
46 * How is that possible!?!?
48 * We'll soon find out.
51 fprintf(stderr
, "No channel\n");
55 if (blen
== 0 && (bp
= malloc(blen
= 512)) == NULL
)
64 for (; *fmt
!= '\0'; ++fmt
)
66 case '1': /* Value #1. */
67 ilen
= htonl(ipbp
->val1
);
69 case '2': /* Value #2. */
70 ilen
= htonl(ipbp
->val2
);
72 case '3': /* Value #3. */
73 ilen
= htonl(ipbp
->val3
);
74 value
: nlen
+= IPO_INT_LEN
;
76 blen
= blen
* 2 + nlen
;
78 if ((bp
= realloc(bp
, blen
)) == NULL
)
82 memcpy(p
, &ilen
, IPO_INT_LEN
);
85 case 'a': /* String #1. */
86 case 'b': /* String #2. */
87 ilen
= *fmt
== 'a' ? ipbp
->len1
: ipbp
->len2
;
88 nlen
+= IPO_INT_LEN
+ ilen
;
90 blen
= blen
* 2 + nlen
;
92 if ((bp
= realloc(bp
, blen
)) == NULL
)
97 memcpy(p
, &ilen
, IPO_INT_LEN
);
100 memcpy(p
, ipbp
->str1
, ipbp
->len1
);
103 memcpy(p
, ipbp
->str2
, ipbp
->len2
);
108 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
109 if ((nw
= write(ofd
, p
, n
)) < 0)