5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "Id: ip_funcs.c,v 8.23 2001/06/25 15:19:23 skimo Exp (Berkeley) Date: 2001/06/25 15:19:23";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
25 #include "../common/common.h"
27 #include "../ipc/ip.h"
32 * Add len bytes from the string at the cursor, advancing the cursor.
34 * PUBLIC: int ip_waddstr __P((SCR *, const CHAR_T *, size_t));
37 ip_waddstr(SCR
*sp
, const CHAR_T
*str
, size_t len
)
45 ipb
.code
= SI_WADDSTR
;
46 ipb
.len1
= len
* sizeof(CHAR_T
);
47 ipb
.str1
= (char *)str
;
48 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
57 * Add len bytes from the string at the cursor, advancing the cursor.
59 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
62 ip_addstr(SCR
*sp
, const char *str
, size_t len
)
71 * If ex isn't in control, it's the last line of the screen and
72 * it's a split screen, use inverse video.
75 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) &&
76 ipp
->row
== LASTLINE(sp
) && IS_SPLIT(sp
)) {
78 ip_attr(sp
, SA_INVERSE
, 1);
83 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
88 ip_attr(sp
, SA_INVERSE
, 0);
94 * Toggle a screen attribute on/off.
96 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
99 ip_attr(SCR
*sp
, scr_attr_t attribute
, int on
)
102 IP_PRIVATE
*ipp
= IPP(sp
);
104 if (attribute
== SA_ALTERNATE
) {
105 if (on
) F_SET(ipp
, IP_ON_ALTERNATE
);
106 else F_CLR(ipp
, IP_ON_ALTERNATE
);
109 ipb
.code
= SI_ATTRIBUTE
;
110 ipb
.val1
= attribute
;
113 return (vi_send(ipp
->o_fd
, "12", &ipb
));
118 * Return the baud rate.
120 * PUBLIC: int ip_baud __P((SCR *, u_long *));
123 ip_baud(SCR
*sp
, u_long
*ratep
)
125 *ratep
= 9600; /* XXX: Translation: fast. */
131 * Ring the bell/flash the screen.
133 * PUBLIC: int ip_bell __P((SCR *));
139 IP_PRIVATE
*ipp
= IPP(sp
);
143 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
148 * Display a busy message.
150 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
153 ip_busy(SCR
*sp
, const char *str
, busy_t bval
)
156 IP_PRIVATE
*ipp
= IPP(sp
);
160 ipb
.code
= SI_BUSY_ON
;
162 ipb
.len1
= strlen(str
);
163 (void)vi_send(ipp
->o_fd
, "a", &ipb
);
166 ipb
.code
= SI_BUSY_OFF
;
167 (void)vi_send(ipp
->o_fd
, NULL
, &ipb
);
179 * PUBLIC: int ip_child __P((SCR *));
184 IP_PRIVATE
*ipp
= IPP(sp
);
186 if (ipp
->t_fd
!= -1) {
197 * Clear from the current cursor to the end of the line.
199 * PUBLIC: int ip_clrtoeol __P((SCR *));
205 IP_PRIVATE
*ipp
= IPP(sp
);
207 /* Temporary hack until we can pass screen pointers
219 for (spcnt
= sp
->cols
- x
;
220 spcnt
> 0 && ! error
; --spcnt
)
221 error
= ip_addstr(sp
, " ", 1);
223 error
|= ip_addstr(sp
, "|", 1);
224 error
|= ip_move(sp
, y
, x
);
228 ipb
.code
= SI_CLRTOEOL
;
230 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
235 * Return the current cursor position.
237 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
240 ip_cursor(SCR
*sp
, size_t *yp
, size_t *xp
)
252 * Delete the current line, scrolling all lines below it.
254 * PUBLIC: int ip_deleteln __P((SCR *));
260 IP_PRIVATE
*ipp
= IPP(sp
);
263 * This clause is required because the curses screen uses reverse
264 * video to delimit split screens. If the screen does not do this,
265 * this code won't be necessary.
267 * If the bottom line was in reverse video, rewrite it in normal
268 * video before it's scrolled.
270 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) && IS_SPLIT(sp
)) {
271 ipb
.code
= SI_REWRITE
;
272 ipb
.val1
= RLNO(sp
, LASTLINE(sp
));
273 if (vi_send(ipp
->o_fd
, "1", &ipb
))
278 * The bottom line is expected to be blank after this operation,
279 * and other screens must support that semantic.
281 ipb
.code
= SI_DELETELN
;
282 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
289 * PUBLIC: int ip_discard __P((SCR *, SCR **));
292 ip_discard(SCR
*discardp
, SCR
**acquirep
)
299 * Adjust the screen for ex.
301 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
304 ip_ex_adjust(SCR
*sp
, exadj_t action
)
312 * Push down the current line, discarding the bottom line.
314 * PUBLIC: int ip_insertln __P((SCR *));
320 IP_PRIVATE
*ipp
= IPP(sp
);
322 ipb
.code
= SI_INSERTLN
;
324 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
329 * Return the value for a special key.
331 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
334 ip_keyval(SCR
*sp
, scr_keyval_t val
, CHAR_T
*chp
, int *dnep
)
337 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
338 * VWERASE is a 4BSD extension.
342 *dnep
= '\004'; /* ^D */
345 *dnep
= '\b'; /* ^H */
348 *dnep
= '\025'; /* ^U */
352 *dnep
= '\027'; /* ^W */
366 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
369 ip_move(SCR
*sp
, size_t lno
, size_t cno
)
379 ipb
.val1
= RLNO(sp
, lno
);
380 ipb
.val2
= RCNO(sp
, cno
);
381 return (vi_send(ipp
->o_fd
, "12", &ipb
));
385 * PUBLIC: void ip_msg __P((SCR *, mtype_t, char *, size_t));
388 ip_msg(SCR
*sp
, mtype_t mtype
, char *line
, size_t len
)
390 IP_PRIVATE
*ipp
= IPP(sp
);
392 if (F_ISSET(ipp
, IP_ON_ALTERNATE
))
393 vs_msg(sp
, mtype
, line
, len
);
395 write(ipp
->t_fd
, line
, len
);
396 F_CLR(sp
, SC_EX_WAIT_NO
);
402 * Refresh the screen.
404 * PUBLIC: int ip_refresh __P((SCR *, int));
407 ip_refresh(SCR
*sp
, int repaint
)
416 * If the scroll bar information has changed since we last sent
417 * it, resend it. Currently, we send three values:
419 * top The line number of the first line in the screen.
420 * num The number of lines visible on the screen.
421 * total The number of lines in the file.
424 * This is a gross violation of layering... we're looking at data
425 * structures at which we have absolutely no business whatsoever
428 ipb
.val1
= HMAP
->lno
;
429 ipb
.val2
= TMAP
->lno
- HMAP
->lno
;
430 if (sp
->ep
!= NULL
&& sp
->ep
->db
!= NULL
)
431 (void)db_last(sp
, &total
);
432 ipb
.val3
= total
== 0 ? 1 : total
;
433 if (ipb
.val1
!= ipp
->sb_top
||
434 ipb
.val2
!= ipp
->sb_num
|| ipb
.val3
!= ipp
->sb_total
) {
435 ipb
.code
= SI_SCROLLBAR
;
436 (void)vi_send(ipp
->o_fd
, "123", &ipb
);
437 ipp
->sb_top
= ipb
.val1
;
438 ipp
->sb_num
= ipb
.val2
;
439 ipp
->sb_total
= ipb
.val3
;
442 /* Refresh/repaint the screen. */
443 ipb
.code
= repaint
? SI_REDRAW
: SI_REFRESH
;
444 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
451 * PUBLIC: int ip_rename __P((SCR *, char *, int));
454 ip_rename(SCR
*sp
, char *name
, int on
)
457 IP_PRIVATE
*ipp
= IPP(sp
);
459 ipb
.code
= SI_RENAME
;
461 ipb
.len1
= name
? strlen(name
) : 0;
462 return (vi_send(ipp
->o_fd
, "a", &ipb
));
467 * Reply to a message.
469 * PUBLIC: int ip_reply __P((SCR *, int, char *));
472 ip_reply(SCR
*sp
, int status
, char *msg
)
475 IP_PRIVATE
*ipp
= IPP(sp
);
479 ipb
.str1
= msg
== NULL
? "" : msg
;
480 ipb
.len1
= strlen(ipb
.str1
);
481 return (vi_send(ipp
->o_fd
, "1a", &ipb
));
488 * PUBLIC: int ip_split __P((SCR *, SCR *));
491 ip_split(SCR
*origp
, SCR
*newp
)
500 * PUBLIC: int ip_suspend __P((SCR *, int *));
503 ip_suspend(SCR
*sp
, int *allowedp
)
511 * Print out the ip usage messages.
513 * PUBLIC: void ip_usage __P((void));
519 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
520 (void)fprintf(stderr
, "%s", USAGE
);