3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
11 static const char sccsid
[] = "$Id: ip_funcs.c,v 8.20 2000/07/14 14:29:22 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:22 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
18 #include <bitstring.h>
23 #include "../common/common.h"
25 #include "../ipc/ip.h"
30 * Add len bytes from the string at the cursor, advancing the cursor.
32 * PUBLIC: int ip_waddstr __P((SCR *, const CHAR_T *, size_t));
35 ip_waddstr(sp
, str
, len
)
43 INT2CHAR(sp
, str
, len
, np
, nlen
);
44 ip_addstr(sp
, np
, nlen
);
49 * Add len bytes from the string at the cursor, advancing the cursor.
51 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
54 ip_addstr(sp
, str
, len
)
66 * If ex isn't in control, it's the last line of the screen and
67 * it's a split screen, use inverse video.
70 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) &&
71 ipp
->row
== LASTLINE(sp
) && IS_SPLIT(sp
)) {
73 ip_attr(sp
, SA_INVERSE
, 1);
78 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
83 ip_attr(sp
, SA_INVERSE
, 0);
89 * Toggle a screen attribute on/off.
91 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
94 ip_attr(sp
, attribute
, on
)
100 IP_PRIVATE
*ipp
= IPP(sp
);
102 if (attribute
== SA_ALTERNATE
) {
103 if (on
) F_SET(ipp
, IP_ON_ALTERNATE
);
104 else F_CLR(ipp
, IP_ON_ALTERNATE
);
107 ipb
.code
= SI_ATTRIBUTE
;
108 ipb
.val1
= attribute
;
111 return (vi_send(ipp
->o_fd
, "12", &ipb
));
116 * Return the baud rate.
118 * PUBLIC: int ip_baud __P((SCR *, u_long *));
125 *ratep
= 9600; /* XXX: Translation: fast. */
131 * Ring the bell/flash the screen.
133 * PUBLIC: int ip_bell __P((SCR *));
140 IP_PRIVATE
*ipp
= IPP(sp
);
144 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
149 * Display a busy message.
151 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
154 ip_busy(sp
, str
, bval
)
160 IP_PRIVATE
*ipp
= IPP(sp
);
164 ipb
.code
= SI_BUSY_ON
;
166 ipb
.len1
= strlen(str
);
167 (void)vi_send(ipp
->o_fd
, "a", &ipb
);
170 ipb
.code
= SI_BUSY_OFF
;
171 (void)vi_send(ipp
->o_fd
, NULL
, &ipb
);
183 * PUBLIC: int ip_child __P((SCR *));
189 IP_PRIVATE
*ipp
= IPP(sp
);
191 if (ipp
->t_fd
!= -1) {
202 * Clear from the current cursor to the end of the line.
204 * PUBLIC: int ip_clrtoeol __P((SCR *));
211 IP_PRIVATE
*ipp
= IPP(sp
);
213 /* Temporary hack until we can pass screen pointers
225 for (spcnt
= sp
->cols
- x
;
226 spcnt
> 0 && ! error
; --spcnt
)
227 error
= ip_addstr(sp
, " ", 1);
229 error
|= ip_addstr(sp
, "|", 1);
230 error
|= ip_move(sp
, y
, x
);
234 ipb
.code
= SI_CLRTOEOL
;
236 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
241 * Return the current cursor position.
243 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
246 ip_cursor(sp
, yp
, xp
)
260 * Delete the current line, scrolling all lines below it.
262 * PUBLIC: int ip_deleteln __P((SCR *));
269 IP_PRIVATE
*ipp
= IPP(sp
);
272 * This clause is required because the curses screen uses reverse
273 * video to delimit split screens. If the screen does not do this,
274 * this code won't be necessary.
276 * If the bottom line was in reverse video, rewrite it in normal
277 * video before it's scrolled.
279 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) && IS_SPLIT(sp
)) {
280 ipb
.code
= SI_REWRITE
;
281 ipb
.val1
= RLNO(sp
, LASTLINE(sp
));
282 if (vi_send(ipp
->o_fd
, "1", &ipb
))
287 * The bottom line is expected to be blank after this operation,
288 * and other screens must support that semantic.
290 ipb
.code
= SI_DELETELN
;
291 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
298 * PUBLIC: int ip_discard __P((SCR *, SCR **));
301 ip_discard(discardp
, acquirep
)
302 SCR
*discardp
, **acquirep
;
309 * Adjust the screen for ex.
311 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
314 ip_ex_adjust(sp
, action
)
324 * Push down the current line, discarding the bottom line.
326 * PUBLIC: int ip_insertln __P((SCR *));
333 IP_PRIVATE
*ipp
= IPP(sp
);
335 ipb
.code
= SI_INSERTLN
;
337 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
342 * Return the value for a special key.
344 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
347 ip_keyval(sp
, val
, chp
, dnep
)
354 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
355 * VWERASE is a 4BSD extension.
359 *dnep
= '\004'; /* ^D */
362 *dnep
= '\b'; /* ^H */
365 *dnep
= '\025'; /* ^U */
369 *dnep
= '\027'; /* ^W */
383 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
386 ip_move(sp
, lno
, cno
)
398 ipb
.val1
= RLNO(sp
, lno
);
399 ipb
.val2
= RCNO(sp
, cno
);
400 return (vi_send(ipp
->o_fd
, "12", &ipb
));
404 * PUBLIC: void ip_msg __P((SCR *, mtype_t, char *, size_t));
407 ip_msg(sp
, mtype
, line
, len
)
413 IP_PRIVATE
*ipp
= IPP(sp
);
415 if (F_ISSET(ipp
, IP_ON_ALTERNATE
))
416 vs_msg(sp
, mtype
, line
, len
);
418 write(ipp
->t_fd
, line
, len
);
419 F_CLR(sp
, SC_EX_WAIT_NO
);
425 * Refresh the screen.
427 * PUBLIC: int ip_refresh __P((SCR *, int));
430 ip_refresh(sp
, repaint
)
441 * If the scroll bar information has changed since we last sent
442 * it, resend it. Currently, we send three values:
444 * top The line number of the first line in the screen.
445 * num The number of lines visible on the screen.
446 * total The number of lines in the file.
449 * This is a gross violation of layering... we're looking at data
450 * structures at which we have absolutely no business whatsoever
453 ipb
.val1
= HMAP
->lno
;
454 ipb
.val2
= TMAP
->lno
- HMAP
->lno
;
455 (void)db_last(sp
, &total
);
456 ipb
.val3
= total
== 0 ? 1 : total
;
457 if (ipb
.val1
!= ipp
->sb_top
||
458 ipb
.val2
!= ipp
->sb_num
|| ipb
.val3
!= ipp
->sb_total
) {
459 ipb
.code
= SI_SCROLLBAR
;
460 (void)vi_send(ipp
->o_fd
, "123", &ipb
);
461 ipp
->sb_top
= ipb
.val1
;
462 ipp
->sb_num
= ipb
.val2
;
463 ipp
->sb_total
= ipb
.val3
;
466 /* Refresh/repaint the screen. */
467 ipb
.code
= repaint
? SI_REDRAW
: SI_REFRESH
;
468 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
475 * PUBLIC: int ip_rename __P((SCR *, char *, int));
478 ip_rename(sp
, name
, on
)
484 IP_PRIVATE
*ipp
= IPP(sp
);
486 ipb
.code
= SI_RENAME
;
488 ipb
.len1
= name
? strlen(name
) : 0;
489 return (vi_send(ipp
->o_fd
, "a", &ipb
));
494 * Reply to a message.
496 * PUBLIC: int ip_reply __P((SCR *, int, char *));
499 ip_reply(sp
, status
, msg
)
505 IP_PRIVATE
*ipp
= IPP(sp
);
509 ipb
.str1
= msg
== NULL
? "" : msg
;
510 ipb
.len1
= strlen(ipb
.str1
);
511 return (vi_send(ipp
->o_fd
, "1a", &ipb
));
518 * PUBLIC: int ip_split __P((SCR *, SCR *));
521 ip_split(origp
, newp
)
531 * PUBLIC: int ip_suspend __P((SCR *, int *));
534 ip_suspend(sp
, allowedp
)
544 * Print out the ip usage messages.
546 * PUBLIC: void ip_usage __P((void));
552 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
553 (void)fprintf(stderr
, "%s", USAGE
);