1 /* $NetBSD: ip_funcs.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
11 #include <sys/cdefs.h>
14 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 ";
17 __RCSID("$NetBSD: ip_funcs.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20 #include <sys/types.h>
21 #include <sys/queue.h>
24 #include <bitstring.h>
30 #include "../common/common.h"
32 #include "../ipc/ip.h"
36 * Add len bytes from the string at the cursor, advancing the cursor.
38 * PUBLIC: int ip_waddstr __P((SCR *, const CHAR_T *, size_t));
41 ip_waddstr(SCR
*sp
, const CHAR_T
*str
, size_t len
)
49 memset(&ipb
, 0, sizeof(ipb
));
50 ipb
.code
= SI_WADDSTR
;
51 ipb
.len1
= len
* sizeof(CHAR_T
);
52 ipb
.str1
= __UNCONST(str
);
53 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
62 * Add len bytes from the string at the cursor, advancing the cursor.
64 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
67 ip_addstr(SCR
*sp
, const char *str
, size_t len
)
76 * If ex isn't in control, it's the last line of the screen and
77 * it's a split screen, use inverse video.
79 memset(&ipb
, 0, sizeof(ipb
));
81 if (!F_ISSET(sp
, SC_SCR_EXWROTE
) &&
82 ipp
->row
== LASTLINE(sp
) && IS_SPLIT(sp
)) {
84 ip_attr(sp
, SA_INVERSE
, 1);
89 rval
= vi_send(ipp
->o_fd
, "a", &ipb
);
94 ip_attr(sp
, SA_INVERSE
, 0);
100 * Toggle a screen attribute on/off.
102 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
105 ip_attr(SCR
*sp
, scr_attr_t attribute
, int on
)
108 IP_PRIVATE
*ipp
= IPP(sp
);
110 memset(&ipb
, 0, sizeof(ipb
));
111 if (attribute
== SA_ALTERNATE
) {
112 if (on
) F_SET(ipp
, IP_ON_ALTERNATE
);
113 else F_CLR(ipp
, IP_ON_ALTERNATE
);
116 ipb
.code
= SI_ATTRIBUTE
;
117 ipb
.val1
= attribute
;
120 return (vi_send(ipp
->o_fd
, "12", &ipb
));
125 * Return the baud rate.
127 * PUBLIC: int ip_baud __P((SCR *, u_long *));
130 ip_baud(SCR
*sp
, u_long
*ratep
)
132 *ratep
= 9600; /* XXX: Translation: fast. */
138 * Ring the bell/flash the screen.
140 * PUBLIC: int ip_bell __P((SCR *));
146 IP_PRIVATE
*ipp
= IPP(sp
);
148 memset(&ipb
, 0, sizeof(ipb
));
151 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
156 * Display a busy message.
158 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
161 ip_busy(SCR
*sp
, const char *str
, busy_t bval
)
164 IP_PRIVATE
*ipp
= IPP(sp
);
166 memset(&ipb
, 0, sizeof(ipb
));
169 ipb
.code
= SI_BUSY_ON
;
171 ipb
.len1
= strlen(str
);
172 (void)vi_send(ipp
->o_fd
, "a", &ipb
);
175 ipb
.code
= SI_BUSY_OFF
;
176 (void)vi_send(ipp
->o_fd
, NULL
, &ipb
);
188 * PUBLIC: int ip_child __P((SCR *));
193 IP_PRIVATE
*ipp
= IPP(sp
);
195 if (ipp
->t_fd
!= -1) {
206 * Clear from the current cursor to the end of the line.
208 * PUBLIC: int ip_clrtoeol __P((SCR *));
214 IP_PRIVATE
*ipp
= IPP(sp
);
216 /* Temporary hack until we can pass screen pointers
219 memset(&ipb
, 0, sizeof(ipb
));
227 for (spcnt
= sp
->cols
- x
;
228 spcnt
> 0 && ! error
; --spcnt
)
229 error
= ip_addstr(sp
, " ", 1);
231 error
|= ip_addstr(sp
, "|", 1);
232 error
|= ip_move(sp
, y
, x
);
236 ipb
.code
= SI_CLRTOEOL
;
238 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
243 * Return the current cursor position.
245 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
248 ip_cursor(SCR
*sp
, size_t *yp
, size_t *xp
)
260 * Delete the current line, scrolling all lines below it.
262 * PUBLIC: int ip_deleteln __P((SCR *));
268 IP_PRIVATE
*ipp
= IPP(sp
);
271 * This clause is required because the curses screen uses reverse
272 * video to delimit split screens. If the screen does not do this,
273 * this code won't be necessary.
275 * If the bottom line was in reverse video, rewrite it in normal
276 * video before it's scrolled.
278 memset(&ipb
, 0, sizeof(ipb
));
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(SCR
*discardp
, SCR
**acquirep
)
308 * Adjust the screen for ex.
310 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
313 ip_ex_adjust(SCR
*sp
, exadj_t action
)
321 * Push down the current line, discarding the bottom line.
323 * PUBLIC: int ip_insertln __P((SCR *));
329 IP_PRIVATE
*ipp
= IPP(sp
);
331 memset(&ipb
, 0, sizeof(ipb
));
332 ipb
.code
= SI_INSERTLN
;
334 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
339 * Return the value for a special key.
341 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
344 ip_keyval(SCR
*sp
, scr_keyval_t val
, CHAR_T
*chp
, int *dnep
)
347 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
348 * VWERASE is a 4BSD extension.
352 *dnep
= '\004'; /* ^D */
355 *dnep
= '\b'; /* ^H */
358 *dnep
= '\025'; /* ^U */
362 *dnep
= '\027'; /* ^W */
376 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
379 ip_move(SCR
*sp
, size_t lno
, size_t cno
)
388 memset(&ipb
, 0, sizeof(ipb
));
390 ipb
.val1
= RLNO(sp
, lno
);
391 ipb
.val2
= RCNO(sp
, cno
);
392 return (vi_send(ipp
->o_fd
, "12", &ipb
));
396 * PUBLIC: void ip_msg __P((SCR *, mtype_t, char *, size_t));
399 ip_msg(SCR
*sp
, mtype_t mtype
, char *line
, size_t len
)
401 IP_PRIVATE
*ipp
= IPP(sp
);
403 if (F_ISSET(ipp
, IP_ON_ALTERNATE
))
404 vs_msg(sp
, mtype
, line
, len
);
406 write(ipp
->t_fd
, line
, len
);
407 F_CLR(sp
, SC_EX_WAIT_NO
);
413 * Refresh the screen.
415 * PUBLIC: int ip_refresh __P((SCR *, int));
418 ip_refresh(SCR
*sp
, int repaint
)
427 * If the scroll bar information has changed since we last sent
428 * it, resend it. Currently, we send three values:
430 * top The line number of the first line in the screen.
431 * num The number of lines visible on the screen.
432 * total The number of lines in the file.
435 * This is a gross violation of layering... we're looking at data
436 * structures at which we have absolutely no business whatsoever
439 memset(&ipb
, 0, sizeof(ipb
));
440 ipb
.val1
= HMAP
->lno
;
441 ipb
.val2
= TMAP
->lno
- HMAP
->lno
;
442 if (sp
->ep
!= NULL
&& sp
->ep
->db
!= NULL
)
443 (void)db_last(sp
, &total
);
444 ipb
.val3
= total
== 0 ? 1 : total
;
445 if (ipb
.val1
!= ipp
->sb_top
||
446 ipb
.val2
!= ipp
->sb_num
|| ipb
.val3
!= ipp
->sb_total
) {
447 ipb
.code
= SI_SCROLLBAR
;
448 (void)vi_send(ipp
->o_fd
, "123", &ipb
);
449 ipp
->sb_top
= ipb
.val1
;
450 ipp
->sb_num
= ipb
.val2
;
451 ipp
->sb_total
= ipb
.val3
;
454 /* Refresh/repaint the screen. */
455 ipb
.code
= repaint
? SI_REDRAW
: SI_REFRESH
;
456 return (vi_send(ipp
->o_fd
, NULL
, &ipb
));
463 * PUBLIC: int ip_rename __P((SCR *, char *, int));
466 ip_rename(SCR
*sp
, char *name
, int on
)
469 IP_PRIVATE
*ipp
= IPP(sp
);
471 memset(&ipb
, 0, sizeof(ipb
));
472 ipb
.code
= SI_RENAME
;
474 ipb
.len1
= name
? strlen(name
) : 0;
475 return (vi_send(ipp
->o_fd
, "a", &ipb
));
480 * Reply to a message.
482 * PUBLIC: int ip_reply __P((SCR *, int, char *));
485 ip_reply(SCR
*sp
, int status
, char *msg
)
488 IP_PRIVATE
*ipp
= IPP(sp
);
490 memset(&ipb
, 0, sizeof(ipb
));
493 ipb
.str1
= msg
== NULL
? "" : msg
;
494 ipb
.len1
= strlen(ipb
.str1
);
495 return (vi_send(ipp
->o_fd
, "1a", &ipb
));
502 * PUBLIC: int ip_split __P((SCR *, SCR *));
505 ip_split(SCR
*origp
, SCR
*newp
)
514 * PUBLIC: int ip_suspend __P((SCR *, int *));
517 ip_suspend(SCR
*sp
, int *allowedp
)
525 * Print out the ip usage messages.
527 * PUBLIC: void ip_usage __P((void));
533 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
534 (void)fprintf(stderr
, "%s", USAGE
);