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.8 1996/12/10 21:01:01 bostic Exp $ (Berkeley) $Date: 1996/12/10 21:01:01 $";
14 #include <sys/types.h>
15 #include <sys/queue.h>
18 #include <bitstring.h>
23 #include "../common/common.h"
26 #include "../include/ipc_extern.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("s", &ipb
);
62 ip_attr(sp
, SA_INVERSE
, 0);
68 * Toggle a screen attribute on/off.
70 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
73 ip_attr(sp
, attribute
, on
)
80 ipb
.code
= SI_ATTRIBUTE
;
84 return (__vi_send("12", &ipb
));
89 * Return the baud rate.
91 * PUBLIC: int ip_baud __P((SCR *, u_long *));
98 *ratep
= 9600; /* XXX: Translation: fast. */
104 * Ring the bell/flash the screen.
106 * PUBLIC: int ip_bell __P((SCR *));
116 return (__vi_send(NULL
, &ipb
));
121 * Display a busy message.
123 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
126 ip_busy(sp
, str
, bval
)
135 ipb
.code
= SI_BUSY_ON
;
136 ipb
.len
= strlen(str
);
138 (void)__vi_send("s1", &ipb
);
141 ipb
.code
= SI_BUSY_OFF
;
142 (void)__vi_send(NULL
, &ipb
);
152 * Clear from the current cursor to the end of the line.
154 * PUBLIC: int ip_clrtoeol __P((SCR *));
162 ipb
.code
= SI_CLRTOEOL
;
164 return (__vi_send(NULL
, &ipb
));
169 * Return the current cursor position.
171 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
174 ip_cursor(sp
, yp
, xp
)
188 * Delete the current line, scrolling all lines below it.
190 * PUBLIC: int ip_deleteln __P((SCR *));
199 * This clause is required because the curses screen uses reverse
200 * video to delimit split screens. If the screen does not do this,
201 * this code won't be necessary.
203 * If the bottom line was in reverse video, rewrite it in normal
204 * video before it's scrolled.
206 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) && IS_SPLIT(sp
)) {
207 ipb
.code
= SI_REWRITE
;
208 ipb
.val1
= RLNO(sp
, LASTLINE(sp
));
209 if (__vi_send("1", &ipb
))
214 * The bottom line is expected to be blank after this operation,
215 * and other screens must support that semantic.
217 ipb
.code
= SI_DELETELN
;
218 return (__vi_send(NULL
, &ipb
));
225 * PUBLIC: int ip_discard __P((SCR *, SCR *));
228 ip_discard(discardp
, acquirep
)
229 SCR
*discardp
, *acquirep
;
236 * Adjust the screen for ex.
238 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
241 ip_ex_adjust(sp
, action
)
251 * Push down the current line, discarding the bottom line.
253 * PUBLIC: int ip_insertln __P((SCR *));
261 ipb
.code
= SI_INSERTLN
;
263 return (__vi_send(NULL
, &ipb
));
268 * Return the value for a special key.
270 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
273 ip_keyval(sp
, val
, chp
, dnep
)
280 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
281 * VWERASE is a 4BSD extension.
285 *dnep
= '\004'; /* ^D */
288 *dnep
= '\b'; /* ^H */
291 *dnep
= '\025'; /* ^U */
295 *dnep
= '\027'; /* ^W */
309 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
312 ip_move(sp
, lno
, cno
)
324 ipb
.val1
= RLNO(sp
, lno
);
326 return (__vi_send("12", &ipb
));
331 * Refresh the screen.
333 * PUBLIC: int ip_refresh __P((SCR *, int));
336 ip_refresh(sp
, repaint
)
348 * If the scroll bar information has changed since we last sent
349 * it, resend it. Currently, we send three values:
351 * top The line number of the first line in the screen.
352 * num The number of lines visible on the screen.
353 * total The number of lines in the file.
356 * This is a gross violation of layering... we're looking at data
357 * structures at which we have absolutely no business whatsoever
361 ipb
.val1
= HMAP
->lno
;
362 ipb
.val2
= TMAP
->lno
- HMAP
->lno
;
363 (void)db_last(sp
, &total
);
365 if (ipb
.val1
!= ipp
->sb_top
||
366 ipb
.val2
!= ipp
->sb_num
|| ipb
.val3
!= ipp
->sb_total
) {
367 ipb
.code
= SI_SCROLLBAR
;
368 (void)__vi_send("123", &ipb
);
369 ipp
->sb_top
= ipb
.val1
;
370 ipp
->sb_num
= ipb
.val2
;
371 ipp
->sb_total
= ipb
.val3
;
374 /* Refresh/repaint the screen. */
375 ipb
.code
= repaint
? SI_REDRAW
: SI_REFRESH
;
376 return (__vi_send(NULL
, &ipb
));
383 * PUBLIC: int ip_rename __P((SCR *, char *, int));
386 ip_rename(sp
, name
, on
)
393 ipb
.code
= SI_RENAME
;
394 ipb
.len
= strlen(name
);
397 return (__vi_send("s", &ipb
));
404 * PUBLIC: int ip_split __P((SCR *, SCR *));
407 ip_split(origp
, newp
)
417 * PUBLIC: int ip_suspend __P((SCR *, int *));
420 ip_suspend(sp
, allowedp
)
430 * Print out the ip usage messages.
432 * PUBLIC: void ip_usage __P((void));
438 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
439 (void)fprintf(stderr
, "%s", USAGE
);