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.16 2000/06/28 20:20:37 skimo Exp $ (Berkeley) $Date: 2000/06/28 20:20:37 $";
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_addstr __P((SCR *, const char *, size_t));
35 ip_addstr(sp
, str
, len
)
47 * If ex isn't in control, it's the last line of the screen and
48 * it's a split screen, use inverse video.
51 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) &&
52 ipp
->row
== LASTLINE(sp
) && IS_SPLIT(sp
)) {
54 ip_attr(sp
, SA_INVERSE
, 1);
59 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
64 ip_attr(sp
, SA_INVERSE
, 0);
70 * Toggle a screen attribute on/off.
72 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
75 ip_attr(sp
, attribute
, on
)
81 IP_PRIVATE
*ipp
= IPP(sp
);
83 ipb
.code
= SI_ATTRIBUTE
;
87 return (vi_send(ipp
->o_fd
, "12", &ipb
));
92 * Return the baud rate.
94 * PUBLIC: int ip_baud __P((SCR *, u_long *));
101 *ratep
= 9600; /* XXX: Translation: fast. */
107 * Ring the bell/flash the screen.
109 * PUBLIC: int ip_bell __P((SCR *));
116 IP_PRIVATE
*ipp
= IPP(sp
);
120 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
125 * Display a busy message.
127 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
130 ip_busy(sp
, str
, bval
)
136 IP_PRIVATE
*ipp
= IPP(sp
);
140 ipb
.code
= SI_BUSY_ON
;
142 ipb
.len1
= strlen(str
);
143 (void)vi_send(ipp
->o_fd
, "a", &ipb
);
146 ipb
.code
= SI_BUSY_OFF
;
147 (void)vi_send(ipp
->o_fd
, NULL
, &ipb
);
157 * Clear from the current cursor to the end of the line.
159 * PUBLIC: int ip_clrtoeol __P((SCR *));
166 IP_PRIVATE
*ipp
= IPP(sp
);
168 /* Temporary hack until we can pass screen pointers
180 for (spcnt
= sp
->cols
- x
;
181 spcnt
> 0 && ! error
; --spcnt
)
182 error
= ip_addstr(sp
, " ", 1);
184 error
|= ip_addstr(sp
, "|", 1);
185 error
|= ip_move(sp
, y
, x
);
189 ipb
.code
= SI_CLRTOEOL
;
191 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
196 * Return the current cursor position.
198 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
201 ip_cursor(sp
, yp
, xp
)
215 * Delete the current line, scrolling all lines below it.
217 * PUBLIC: int ip_deleteln __P((SCR *));
224 IP_PRIVATE
*ipp
= IPP(sp
);
227 * This clause is required because the curses screen uses reverse
228 * video to delimit split screens. If the screen does not do this,
229 * this code won't be necessary.
231 * If the bottom line was in reverse video, rewrite it in normal
232 * video before it's scrolled.
234 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) && IS_SPLIT(sp
)) {
235 ipb
.code
= SI_REWRITE
;
236 ipb
.val1
= RLNO(sp
, LASTLINE(sp
));
237 if (vi_send(ipp
->o_fd
, "1", &ipb
))
242 * The bottom line is expected to be blank after this operation,
243 * and other screens must support that semantic.
245 ipb
.code
= SI_DELETELN
;
246 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
253 * PUBLIC: int ip_discard __P((SCR *, SCR **));
256 ip_discard(discardp
, acquirep
)
257 SCR
*discardp
, **acquirep
;
264 * Adjust the screen for ex.
266 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
269 ip_ex_adjust(sp
, action
)
279 * Push down the current line, discarding the bottom line.
281 * PUBLIC: int ip_insertln __P((SCR *));
288 IP_PRIVATE
*ipp
= IPP(sp
);
290 ipb
.code
= SI_INSERTLN
;
292 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
297 * Return the value for a special key.
299 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
302 ip_keyval(sp
, val
, chp
, dnep
)
309 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
310 * VWERASE is a 4BSD extension.
314 *dnep
= '\004'; /* ^D */
317 *dnep
= '\b'; /* ^H */
320 *dnep
= '\025'; /* ^U */
324 *dnep
= '\027'; /* ^W */
338 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
341 ip_move(sp
, lno
, cno
)
353 ipb
.val1
= RLNO(sp
, lno
);
354 ipb
.val2
= RCNO(sp
, cno
);
355 return (vi_send(ipp
->o_fd
, "12", &ipb
));
360 * Refresh the screen.
362 * PUBLIC: int ip_refresh __P((SCR *, int));
365 ip_refresh(sp
, repaint
)
376 * If the scroll bar information has changed since we last sent
377 * it, resend it. Currently, we send three values:
379 * top The line number of the first line in the screen.
380 * num The number of lines visible on the screen.
381 * total The number of lines in the file.
384 * This is a gross violation of layering... we're looking at data
385 * structures at which we have absolutely no business whatsoever
388 ipb
.val1
= HMAP
->lno
;
389 ipb
.val2
= TMAP
->lno
- HMAP
->lno
;
390 (void)db_last(sp
, &total
);
391 ipb
.val3
= total
== 0 ? 1 : total
;
392 if (ipb
.val1
!= ipp
->sb_top
||
393 ipb
.val2
!= ipp
->sb_num
|| ipb
.val3
!= ipp
->sb_total
) {
394 ipb
.code
= SI_SCROLLBAR
;
395 (void)vi_send(ipp
->o_fd
, "123", &ipb
);
396 ipp
->sb_top
= ipb
.val1
;
397 ipp
->sb_num
= ipb
.val2
;
398 ipp
->sb_total
= ipb
.val3
;
401 /* Refresh/repaint the screen. */
402 ipb
.code
= repaint
? SI_REDRAW
: SI_REFRESH
;
403 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
410 * PUBLIC: int ip_rename __P((SCR *, char *, int));
413 ip_rename(sp
, name
, on
)
419 IP_PRIVATE
*ipp
= IPP(sp
);
421 ipb
.code
= SI_RENAME
;
423 ipb
.len1
= strlen(name
);
424 return (vi_send(ipp
->o_fd
, "a", &ipb
));
429 * Reply to a message.
431 * PUBLIC: int ip_reply __P((SCR *, int, char *));
434 ip_reply(sp
, status
, msg
)
440 IP_PRIVATE
*ipp
= IPP(sp
);
444 ipb
.str1
= msg
== NULL
? "" : msg
;
445 ipb
.len1
= strlen(ipb
.str1
);
446 return (vi_send(ipp
->o_fd
, "1a", &ipb
));
453 * PUBLIC: int ip_split __P((SCR *, SCR *));
456 ip_split(origp
, newp
)
466 * PUBLIC: int ip_suspend __P((SCR *, int *));
469 ip_suspend(sp
, allowedp
)
479 * Print out the ip usage messages.
481 * PUBLIC: void ip_usage __P((void));
487 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
488 (void)fprintf(stderr
, "%s", USAGE
);