1 /* $NetBSD: ip_funcs.c,v 1.3 2013/11/27 17:55:46 christos Exp $ */
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
12 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 ";
15 #include <sys/types.h>
16 #include <sys/queue.h>
19 #include <bitstring.h>
25 #include "../common/common.h"
27 #include "../ipc/ip.h"
31 * Add len bytes from the string at the cursor, advancing the cursor.
33 * PUBLIC: int ip_waddstr __P((SCR *, const CHAR_T *, size_t));
36 ip_waddstr(SCR
*sp
, const CHAR_T
*str
, size_t len
)
44 memset(&ipb
, 0, sizeof(ipb
));
45 ipb
.code
= SI_WADDSTR
;
46 ipb
.len1
= len
* sizeof(CHAR_T
);
47 ipb
.str1
= __UNCONST(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.
74 memset(&ipb
, 0, sizeof(ipb
));
76 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) &&
77 ipp
->row
== LASTLINE(sp
) && IS_SPLIT(sp
)) {
79 ip_attr(sp
, SA_INVERSE
, 1);
84 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
89 ip_attr(sp
, SA_INVERSE
, 0);
95 * Toggle a screen attribute on/off.
97 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
100 ip_attr(SCR
*sp
, scr_attr_t attribute
, int on
)
103 IP_PRIVATE
*ipp
= IPP(sp
);
105 memset(&ipb
, 0, sizeof(ipb
));
106 if (attribute
== SA_ALTERNATE
) {
107 if (on
) F_SET(ipp
, IP_ON_ALTERNATE
);
108 else F_CLR(ipp
, IP_ON_ALTERNATE
);
111 ipb
.code
= SI_ATTRIBUTE
;
112 ipb
.val1
= attribute
;
115 return (vi_send(ipp
->o_fd
, "12", &ipb
));
120 * Return the baud rate.
122 * PUBLIC: int ip_baud __P((SCR *, u_long *));
125 ip_baud(SCR
*sp
, u_long
*ratep
)
127 *ratep
= 9600; /* XXX: Translation: fast. */
133 * Ring the bell/flash the screen.
135 * PUBLIC: int ip_bell __P((SCR *));
141 IP_PRIVATE
*ipp
= IPP(sp
);
143 memset(&ipb
, 0, sizeof(ipb
));
146 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
151 * Display a busy message.
153 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
156 ip_busy(SCR
*sp
, const char *str
, busy_t bval
)
159 IP_PRIVATE
*ipp
= IPP(sp
);
161 memset(&ipb
, 0, sizeof(ipb
));
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 *));
188 IP_PRIVATE
*ipp
= IPP(sp
);
190 if (ipp
->t_fd
!= -1) {
201 * Clear from the current cursor to the end of the line.
203 * PUBLIC: int ip_clrtoeol __P((SCR *));
209 IP_PRIVATE
*ipp
= IPP(sp
);
211 /* Temporary hack until we can pass screen pointers
214 memset(&ipb
, 0, sizeof(ipb
));
222 for (spcnt
= sp
->cols
- x
;
223 spcnt
> 0 && ! error
; --spcnt
)
224 error
= ip_addstr(sp
, " ", 1);
226 error
|= ip_addstr(sp
, "|", 1);
227 error
|= ip_move(sp
, y
, x
);
231 ipb
.code
= SI_CLRTOEOL
;
233 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
238 * Return the current cursor position.
240 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
243 ip_cursor(SCR
*sp
, size_t *yp
, size_t *xp
)
255 * Delete the current line, scrolling all lines below it.
257 * PUBLIC: int ip_deleteln __P((SCR *));
263 IP_PRIVATE
*ipp
= IPP(sp
);
266 * This clause is required because the curses screen uses reverse
267 * video to delimit split screens. If the screen does not do this,
268 * this code won't be necessary.
270 * If the bottom line was in reverse video, rewrite it in normal
271 * video before it's scrolled.
273 memset(&ipb
, 0, sizeof(ipb
));
274 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) && IS_SPLIT(sp
)) {
275 ipb
.code
= SI_REWRITE
;
276 ipb
.val1
= RLNO(sp
, LASTLINE(sp
));
277 if (vi_send(ipp
->o_fd
, "1", &ipb
))
282 * The bottom line is expected to be blank after this operation,
283 * and other screens must support that semantic.
285 ipb
.code
= SI_DELETELN
;
286 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
293 * PUBLIC: int ip_discard __P((SCR *, SCR **));
296 ip_discard(SCR
*discardp
, SCR
**acquirep
)
303 * Adjust the screen for ex.
305 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
308 ip_ex_adjust(SCR
*sp
, exadj_t action
)
316 * Push down the current line, discarding the bottom line.
318 * PUBLIC: int ip_insertln __P((SCR *));
324 IP_PRIVATE
*ipp
= IPP(sp
);
326 memset(&ipb
, 0, sizeof(ipb
));
327 ipb
.code
= SI_INSERTLN
;
329 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
334 * Return the value for a special key.
336 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
339 ip_keyval(SCR
*sp
, scr_keyval_t val
, CHAR_T
*chp
, int *dnep
)
342 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
343 * VWERASE is a 4BSD extension.
347 *dnep
= '\004'; /* ^D */
350 *dnep
= '\b'; /* ^H */
353 *dnep
= '\025'; /* ^U */
357 *dnep
= '\027'; /* ^W */
371 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
374 ip_move(SCR
*sp
, size_t lno
, size_t cno
)
383 memset(&ipb
, 0, sizeof(ipb
));
385 ipb
.val1
= RLNO(sp
, lno
);
386 ipb
.val2
= RCNO(sp
, cno
);
387 return (vi_send(ipp
->o_fd
, "12", &ipb
));
391 * PUBLIC: void ip_msg __P((SCR *, mtype_t, char *, size_t));
394 ip_msg(SCR
*sp
, mtype_t mtype
, char *line
, size_t len
)
396 IP_PRIVATE
*ipp
= IPP(sp
);
398 if (F_ISSET(ipp
, IP_ON_ALTERNATE
))
399 vs_msg(sp
, mtype
, line
, len
);
401 write(ipp
->t_fd
, line
, len
);
402 F_CLR(sp
, SC_EX_WAIT_NO
);
408 * Refresh the screen.
410 * PUBLIC: int ip_refresh __P((SCR *, int));
413 ip_refresh(SCR
*sp
, int repaint
)
422 * If the scroll bar information has changed since we last sent
423 * it, resend it. Currently, we send three values:
425 * top The line number of the first line in the screen.
426 * num The number of lines visible on the screen.
427 * total The number of lines in the file.
430 * This is a gross violation of layering... we're looking at data
431 * structures at which we have absolutely no business whatsoever
434 memset(&ipb
, 0, sizeof(ipb
));
435 ipb
.val1
= HMAP
->lno
;
436 ipb
.val2
= TMAP
->lno
- HMAP
->lno
;
437 if (sp
->ep
!= NULL
&& sp
->ep
->db
!= NULL
)
438 (void)db_last(sp
, &total
);
439 ipb
.val3
= total
== 0 ? 1 : total
;
440 if (ipb
.val1
!= ipp
->sb_top
||
441 ipb
.val2
!= ipp
->sb_num
|| ipb
.val3
!= ipp
->sb_total
) {
442 ipb
.code
= SI_SCROLLBAR
;
443 (void)vi_send(ipp
->o_fd
, "123", &ipb
);
444 ipp
->sb_top
= ipb
.val1
;
445 ipp
->sb_num
= ipb
.val2
;
446 ipp
->sb_total
= ipb
.val3
;
449 /* Refresh/repaint the screen. */
450 ipb
.code
= repaint
? SI_REDRAW
: SI_REFRESH
;
451 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
458 * PUBLIC: int ip_rename __P((SCR *, char *, int));
461 ip_rename(SCR
*sp
, char *name
, int on
)
464 IP_PRIVATE
*ipp
= IPP(sp
);
466 memset(&ipb
, 0, sizeof(ipb
));
467 ipb
.code
= SI_RENAME
;
469 ipb
.len1
= name
? strlen(name
) : 0;
470 return (vi_send(ipp
->o_fd
, "a", &ipb
));
475 * Reply to a message.
477 * PUBLIC: int ip_reply __P((SCR *, int, char *));
480 ip_reply(SCR
*sp
, int status
, char *msg
)
483 IP_PRIVATE
*ipp
= IPP(sp
);
485 memset(&ipb
, 0, sizeof(ipb
));
488 ipb
.str1
= msg
== NULL
? "" : msg
;
489 ipb
.len1
= strlen(ipb
.str1
);
490 return (vi_send(ipp
->o_fd
, "1a", &ipb
));
497 * PUBLIC: int ip_split __P((SCR *, SCR *));
500 ip_split(SCR
*origp
, SCR
*newp
)
509 * PUBLIC: int ip_suspend __P((SCR *, int *));
512 ip_suspend(SCR
*sp
, int *allowedp
)
520 * Print out the ip usage messages.
522 * PUBLIC: void ip_usage __P((void));
528 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
529 (void)fprintf(stderr
, "%s", USAGE
);