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.4 1996/12/11 20:57:03 bostic Exp $ (Berkeley) $Date: 1996/12/11 20:57:03 $";
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 memmove(p
, &ilen
, IPO_INT_LEN
);
86 case 's': /* String. */
87 ilen
= ipbp
->len
; /* XXX: conversion. */
89 nlen
+= IPO_INT_LEN
+ ipbp
->len
;
91 blen
= blen
* 2 + nlen
;
93 if ((bp
= realloc(bp
, blen
)) == NULL
)
97 memmove(p
, &ilen
, IPO_INT_LEN
);
99 memmove(p
, ipbp
->str
, ipbp
->len
);
103 for (n
= p
- bp
, p
= bp
; n
> 0; n
-= nw
, p
+= nw
)
104 if ((nw
= write(vi_ofd
, p
, n
)) < 0)