3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid[] = "@(#)ip_funcs.c 8.4 (Berkeley) 10/13/96";
14 #include <sys/types.h>
15 #include <sys/queue.h>
18 #include <bitstring.h>
21 #include "../common/common.h"
25 static int ip_send __P((SCR *, char *, IP_BUF *));
29 * Add len bytes from the string at the cursor, advancing the cursor.
31 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
34 ip_addstr(sp, str, len)
46 * If ex isn't in control, it's the last line of the screen and
47 * it's a split screen, use inverse video.
50 if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
51 ipp->row == LASTLINE(sp) && IS_SPLIT(sp)) {
53 ip_attr(sp, SA_INVERSE, 1);
55 ipb.code = IPO_ADDSTR;
58 rval = ip_send(sp, "s", &ipb);
61 ip_attr(sp, SA_INVERSE, 0);
67 * Toggle a screen attribute on/off.
69 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
72 ip_attr(sp, attribute, on)
79 ipb.code = IPO_ATTRIBUTE;
83 return (ip_send(sp, "12", &ipb));
88 * Return the baud rate.
90 * PUBLIC: int ip_baud __P((SCR *, u_long *));
97 *ratep = 9600; /* XXX: Translation: fast. */
103 * Ring the bell/flash the screen.
105 * PUBLIC: int ip_bell __P((SCR *));
115 return (ip_send(sp, NULL, &ipb));
120 * Display a busy message.
122 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
125 ip_busy(sp, str, bval)
137 ipb.len = strlen(str);
142 (void)ip_send(sp, "s1", &ipb);
147 * Clear from the current cursor to the end of the line.
149 * PUBLIC: int ip_clrtoeol __P((SCR *));
157 ipb.code = IPO_CLRTOEOL;
159 return (ip_send(sp, NULL, &ipb));
164 * Return the current cursor position.
166 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
169 ip_cursor(sp, yp, xp)
183 * Delete the current line, scrolling all lines below it.
185 * PUBLIC: int ip_deleteln __P((SCR *));
194 * This clause is required because the curses screen uses reverse
195 * video to delimit split screens. If the screen does not do this,
196 * this code won't be necessary.
198 * If the bottom line was in reverse video, rewrite it in normal
199 * video before it's scrolled.
201 if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
202 ipb.code = IPO_REWRITE;
203 ipb.val1 = RLNO(sp, LASTLINE(sp));
204 if (ip_send(sp, "1", &ipb))
209 * The bottom line is expected to be blank after this operation,
210 * and other screens must support that semantic.
212 ipb.code = IPO_DELETELN;
213 return (ip_send(sp, NULL, &ipb));
218 * Adjust the screen for ex.
220 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
223 ip_ex_adjust(sp, action)
233 * Push down the current line, discarding the bottom line.
235 * PUBLIC: int ip_insertln __P((SCR *));
243 ipb.code = IPO_INSERTLN;
245 return (ip_send(sp, NULL, &ipb));
250 * Return the value for a special key.
252 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
255 ip_keyval(sp, val, chp, dnep)
262 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
263 * VWERASE is a 4BSD extension.
267 *dnep = '\004'; /* ^D */
270 *dnep = '\b'; /* ^H */
273 *dnep = '\025'; /* ^U */
277 *dnep = '\027'; /* ^W */
291 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
294 ip_move(sp, lno, cno)
306 ipb.val1 = RLNO(sp, lno);
308 return (ip_send(sp, "12", &ipb));
313 * Refresh the screen.
315 * PUBLIC: int ip_refresh __P((SCR *, int));
318 ip_refresh(sp, repaint)
324 ipb.code = repaint ? IPO_REDRAW : IPO_REFRESH;
326 return (ip_send(sp, NULL, &ipb));
333 * PUBLIC: int ip_rename __P((SCR *));
341 ipb.code = IPO_RENAME;
342 ipb.len = strlen(sp->frp->name);
343 ipb.str = sp->frp->name;
345 return (ip_send(sp, "s", &ipb));
352 * PUBLIC: int ip_suspend __P((SCR *, int *));
355 ip_suspend(sp, allowedp)
365 * Print out the ip usage messages.
367 * PUBLIC: void ip_usage __P((void));
373 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
374 (void)fprintf(stderr, "%s", USAGE);
380 * Construct and send an IP buffer.
383 ip_send(sp, fmt, ipbp)
391 int nlen, n, nw, rval;
396 GET_SPACE_RET(sp, bp, blen, 128);
401 nlen += IPO_CODE_LEN;
404 for (; *fmt != '\0'; ++fmt)
406 case '1': /* Value 1. */
407 ilen = htonl(ipbp->val1);
409 case '2': /* Value 2. */
410 ilen = htonl(ipbp->val2);
411 value: nlen += IPO_INT_LEN;
413 ADD_SPACE_RET(sp, bp, blen, nlen);
415 memmove(p, &ilen, IPO_INT_LEN);
418 case 's': /* String. */
419 ilen = ipbp->len; /* XXX: conversion. */
421 nlen += IPO_INT_LEN + ipbp->len;
423 ADD_SPACE_RET(sp, bp, blen, nlen);
425 memmove(p, &ilen, IPO_INT_LEN);
427 memmove(p, ipbp->str, ipbp->len);
434 for (n = p - bp, p = bp; n > 0; n -= nw, p += nw)
435 if ((nw = write(ipp->o_fd, p, n)) < 0) {
440 FREE_SPACE(sp, bp, blen);