Nobody seems to use the Motif front-end. It's rather broken.
[nvi.git] / cl / cl_funcs.c
blobf09fd90ead55e3b3a1ee35c96f5af3a8f7366d4c
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: cl_funcs.c,v 10.70 2001/06/13 20:00:18 skimo Exp $ (Berkeley) $Date: 2001/06/13 20:00:18 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <termios.h>
27 #include <unistd.h>
29 #include "../common/common.h"
30 #include "../vi/vi.h"
31 #include "cl.h"
33 static void cl_rdiv __P((SCR *));
35 static int
36 addstr4(SCR *sp, void *str, size_t len, int wide)
38 CL_PRIVATE *clp;
39 WINDOW *win;
40 size_t y, x;
41 int iv;
43 clp = CLP(sp);
44 win = CLSP(sp) ? CLSP(sp) : stdscr;
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.
50 iv = 0;
51 getyx(win, y, x);
52 if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
53 y == RLNO(sp, LASTLINE(sp)) && IS_SPLIT(sp)) {
54 iv = 1;
55 (void)wstandout(win);
58 #ifdef USE_WIDECHAR
59 if (wide) {
60 if (waddnwstr(win, str, len) == ERR)
61 return (1);
62 } else
63 #endif
64 if (waddnstr(win, str, len) == ERR)
65 return (1);
67 if (iv)
68 (void)wstandend(win);
69 return (0);
73 * cl_waddstr --
74 * Add len bytes from the string at the cursor, advancing the cursor.
76 * PUBLIC: int cl_waddstr __P((SCR *, const CHAR_T *, size_t));
78 int
79 cl_waddstr(sp, str, len)
80 SCR *sp;
81 const CHAR_T *str;
82 size_t len;
84 addstr4(sp, (void *)str, len, 1);
88 * cl_addstr --
89 * Add len bytes from the string at the cursor, advancing the cursor.
91 * PUBLIC: int cl_addstr __P((SCR *, const char *, size_t));
93 int
94 cl_addstr(sp, str, len)
95 SCR *sp;
96 const char *str;
97 size_t len;
99 addstr4(sp, (void *)str, len, 0);
103 * cl_attr --
104 * Toggle a screen attribute on/off.
106 * PUBLIC: int cl_attr __P((SCR *, scr_attr_t, int));
109 cl_attr(sp, attribute, on)
110 SCR *sp;
111 scr_attr_t attribute;
112 int on;
114 CL_PRIVATE *clp;
115 WINDOW *win;
117 clp = CLP(sp);
118 win = CLSP(sp) ? CLSP(sp) : stdscr;
120 switch (attribute) {
121 case SA_ALTERNATE:
123 * !!!
124 * There's a major layering violation here. The problem is that the
125 * X11 xterm screen has what's known as an "alternate" screen. Some
126 * xterm termcap/terminfo entries include sequences to switch to/from
127 * that alternate screen as part of the ti/te (smcup/rmcup) strings.
128 * Vi runs in the alternate screen, so that you are returned to the
129 * same screen contents on exit from vi that you had when you entered
130 * vi. Further, when you run :shell, or :!date or similar ex commands,
131 * you also see the original screen contents. This wasn't deliberate
132 * on vi's part, it's just that it historically sent terminal init/end
133 * sequences at those times, and the addition of the alternate screen
134 * sequences to the strings changed the behavior of vi. The problem
135 * caused by this is that we don't want to switch back to the alternate
136 * screen while getting a new command from the user, when the user is
137 * continuing to enter ex commands, e.g.:
139 * :!date <<< switch to original screen
140 * [Hit return to continue] <<< prompt user to continue
141 * :command <<< get command from user
143 * Note that the :command input is a true vi input mode, e.g., input
144 * maps and abbreviations are being done. So, we need to be able to
145 * switch back into the vi screen mode, without flashing the screen.
147 * To make matters worse, the curses initscr() and endwin() calls will
148 * do this automatically -- so, this attribute isn't as controlled by
149 * the higher level screen as closely as one might like.
151 if (on) {
152 if (clp->ti_te != TI_SENT) {
153 clp->ti_te = TI_SENT;
154 if (clp->smcup == NULL)
155 (void)cl_getcap(sp, "smcup", &clp->smcup);
156 if (clp->smcup != NULL)
157 (void)tputs(clp->smcup, 1, cl_putchar);
159 } else
160 if (clp->ti_te != TE_SENT) {
161 clp->ti_te = TE_SENT;
162 if (clp->rmcup == NULL)
163 (void)cl_getcap(sp, "rmcup", &clp->rmcup);
164 if (clp->rmcup != NULL)
165 (void)tputs(clp->rmcup, 1, cl_putchar);
166 (void)fflush(stdout);
168 (void)fflush(stdout);
169 break;
170 case SA_INVERSE:
171 if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)) {
172 if (clp->smso == NULL)
173 return (1);
174 if (on)
175 (void)tputs(clp->smso, 1, cl_putchar);
176 else
177 (void)tputs(clp->rmso, 1, cl_putchar);
178 (void)fflush(stdout);
179 } else {
180 if (on)
181 (void)wstandout(win);
182 else
183 (void)wstandend(win);
185 break;
186 default:
187 abort();
189 return (0);
193 * cl_baud --
194 * Return the baud rate.
196 * PUBLIC: int cl_baud __P((SCR *, u_long *));
199 cl_baud(sp, ratep)
200 SCR *sp;
201 u_long *ratep;
203 CL_PRIVATE *clp;
206 * XXX
207 * There's no portable way to get a "baud rate" -- cfgetospeed(3)
208 * returns the value associated with some #define, which we may
209 * never have heard of, or which may be a purely local speed. Vi
210 * only cares if it's SLOW (w300), slow (w1200) or fast (w9600).
211 * Try and detect the slow ones, and default to fast.
213 clp = CLP(sp);
214 switch (cfgetospeed(&clp->orig)) {
215 case B50:
216 case B75:
217 case B110:
218 case B134:
219 case B150:
220 case B200:
221 case B300:
222 case B600:
223 *ratep = 600;
224 break;
225 case B1200:
226 *ratep = 1200;
227 break;
228 default:
229 *ratep = 9600;
230 break;
232 return (0);
236 * cl_bell --
237 * Ring the bell/flash the screen.
239 * PUBLIC: int cl_bell __P((SCR *));
242 cl_bell(sp)
243 SCR *sp;
245 if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE | SC_SCR_EX))
246 (void)write(STDOUT_FILENO, "\07", 1); /* \a */
247 else {
249 * Vi has an edit option which determines if the terminal
250 * should be beeped or the screen flashed.
252 if (O_ISSET(sp, O_FLASH))
253 (void)flash();
254 else
255 (void)beep();
257 return (0);
261 * cl_clrtoeol --
262 * Clear from the current cursor to the end of the line.
264 * PUBLIC: int cl_clrtoeol __P((SCR *));
267 cl_clrtoeol(sp)
268 SCR *sp;
270 WINDOW *win;
271 size_t spcnt, y, x;
273 win = CLSP(sp) ? CLSP(sp) : stdscr;
275 #if 0
276 if (IS_VSPLIT(sp)) {
277 /* The cursor must be returned to its original position. */
278 getyx(win, y, x);
279 for (spcnt = (sp->coff + sp->cols) - x; spcnt > 0; --spcnt)
280 (void)waddch(win, ' ');
281 (void)wmove(win, y, x);
282 return (0);
283 } else
284 #endif
285 return (wclrtoeol(win) == ERR);
289 * cl_cursor --
290 * Return the current cursor position.
292 * PUBLIC: int cl_cursor __P((SCR *, size_t *, size_t *));
295 cl_cursor(sp, yp, xp)
296 SCR *sp;
297 size_t *yp, *xp;
299 WINDOW *win;
300 win = CLSP(sp) ? CLSP(sp) : stdscr;
302 * The curses screen support splits a single underlying curses screen
303 * into multiple screens to support split screen semantics. For this
304 * reason the returned value must be adjusted to be relative to the
305 * current screen, and not absolute. Screens that implement the split
306 * using physically distinct screens won't need this hack.
308 getyx(win, *yp, *xp);
310 *yp -= sp->roff;
311 *xp -= sp->coff;
313 return (0);
317 * cl_deleteln --
318 * Delete the current line, scrolling all lines below it.
320 * PUBLIC: int cl_deleteln __P((SCR *));
323 cl_deleteln(sp)
324 SCR *sp;
326 CHAR_T ch;
327 CL_PRIVATE *clp;
328 WINDOW *win;
329 size_t col, lno, spcnt, y, x;
331 clp = CLP(sp);
332 win = CLSP(sp) ? CLSP(sp) : stdscr;
335 * This clause is required because the curses screen uses reverse
336 * video to delimit split screens. If the screen does not do this,
337 * this code won't be necessary.
339 * If the bottom line was in reverse video, rewrite it in normal
340 * video before it's scrolled.
342 * Check for the existence of a chgat function; XSI requires it, but
343 * historic implementations of System V curses don't. If it's not
344 * a #define, we'll fall back to doing it by hand, which is slow but
345 * acceptable.
347 * By hand means walking through the line, retrieving and rewriting
348 * each character. Curses has no EOL marker, so track strings of
349 * spaces, and copy the trailing spaces only if there's a non-space
350 * character following.
352 if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
353 getyx(win, y, x);
354 #ifdef mvchgat
355 mvwchgat(win, RLNO(sp, LASTLINE(sp)), 0, -1, A_NORMAL, 0, NULL);
356 #else
357 for (lno = RLNO(sp, LASTLINE(sp)), col = spcnt = 0;;) {
358 (void)wmove(win, lno, col);
359 ch = winch(win);
360 if (isblank(ch))
361 ++spcnt;
362 else {
363 (void)wmove(win, lno, col - spcnt);
364 for (; spcnt > 0; --spcnt)
365 (void)waddch(win, ' ');
366 (void)waddch(win, ch);
368 if (++col >= sp->cols)
369 break;
371 #endif
372 (void)wmove(win, y, x);
376 * The bottom line is expected to be blank after this operation,
377 * and other screens must support that semantic.
379 return (wdeleteln(win) == ERR);
383 * cl_discard --
384 * Discard a screen.
386 * PUBLIC: int cl_discard __P((SCR *, SCR **));
389 cl_discard(discardp, acquirep)
390 SCR *discardp, **acquirep;
392 CL_PRIVATE *clp;
393 SCR* tsp;
395 if (discardp) {
396 clp = CLP(discardp);
397 F_SET(clp, CL_LAYOUT);
399 if (CLSP(discardp)) {
400 delwin(CLSP(discardp));
401 CLSP(discardp) = NULL;
405 /* no screens got a piece; we're done */
406 if (!acquirep)
407 return 0;
409 for (; (tsp = *acquirep) != NULL; ++acquirep) {
410 clp = CLP(tsp);
411 F_SET(clp, CL_LAYOUT);
413 if (CLSP(tsp))
414 delwin(CLSP(tsp));
415 CLSP(tsp) = subwin(stdscr, tsp->rows, tsp->cols,
416 tsp->roff, tsp->coff);
419 /* discardp is going away, acquirep is taking up its space. */
420 return (0);
424 * cl_ex_adjust --
425 * Adjust the screen for ex. This routine is purely for standalone
426 * ex programs. All special purpose, all special case.
428 * PUBLIC: int cl_ex_adjust __P((SCR *, exadj_t));
431 cl_ex_adjust(sp, action)
432 SCR *sp;
433 exadj_t action;
435 CL_PRIVATE *clp;
436 int cnt;
438 clp = CLP(sp);
439 switch (action) {
440 case EX_TERM_SCROLL:
441 /* Move the cursor up one line if that's possible. */
442 if (clp->cuu1 != NULL)
443 (void)tputs(clp->cuu1, 1, cl_putchar);
444 else if (clp->cup != NULL)
445 (void)tputs(tgoto(clp->cup,
446 0, LINES - 2), 1, cl_putchar);
447 else
448 return (0);
449 /* FALLTHROUGH */
450 case EX_TERM_CE:
451 /* Clear the line. */
452 if (clp->el != NULL) {
453 (void)putchar('\r');
454 (void)tputs(clp->el, 1, cl_putchar);
455 } else {
457 * Historically, ex didn't erase the line, so, if the
458 * displayed line was only a single glyph, and <eof>
459 * was more than one glyph, the output would not fully
460 * overwrite the user's input. To fix this, output
461 * the maxiumum character number of spaces. Note,
462 * this won't help if the user entered extra prompt
463 * or <blank> characters before the command character.
464 * We'd have to do a lot of work to make that work, and
465 * it's almost certainly not worth the effort.
467 for (cnt = 0; cnt < MAX_CHARACTER_COLUMNS; ++cnt)
468 (void)putchar('\b');
469 for (cnt = 0; cnt < MAX_CHARACTER_COLUMNS; ++cnt)
470 (void)putchar(' ');
471 (void)putchar('\r');
472 (void)fflush(stdout);
474 break;
475 default:
476 abort();
478 return (0);
482 * cl_insertln --
483 * Push down the current line, discarding the bottom line.
485 * PUBLIC: int cl_insertln __P((SCR *));
488 cl_insertln(sp)
489 SCR *sp;
491 WINDOW *win;
492 win = CLSP(sp) ? CLSP(sp) : stdscr;
494 * The current line is expected to be blank after this operation,
495 * and the screen must support that semantic.
497 return (winsertln(win) == ERR);
501 * cl_keyval --
502 * Return the value for a special key.
504 * PUBLIC: int cl_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
507 cl_keyval(sp, val, chp, dnep)
508 SCR *sp;
509 scr_keyval_t val;
510 CHAR_T *chp;
511 int *dnep;
513 CL_PRIVATE *clp;
516 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
517 * VWERASE is a 4BSD extension.
519 clp = CLP(sp);
520 switch (val) {
521 case KEY_VEOF:
522 *dnep = (*chp = clp->orig.c_cc[VEOF]) == _POSIX_VDISABLE;
523 break;
524 case KEY_VERASE:
525 *dnep = (*chp = clp->orig.c_cc[VERASE]) == _POSIX_VDISABLE;
526 break;
527 case KEY_VKILL:
528 *dnep = (*chp = clp->orig.c_cc[VKILL]) == _POSIX_VDISABLE;
529 break;
530 #ifdef VWERASE
531 case KEY_VWERASE:
532 *dnep = (*chp = clp->orig.c_cc[VWERASE]) == _POSIX_VDISABLE;
533 break;
534 #endif
535 default:
536 *dnep = 1;
537 break;
539 return (0);
543 * cl_move --
544 * Move the cursor.
546 * PUBLIC: int cl_move __P((SCR *, size_t, size_t));
549 cl_move(sp, lno, cno)
550 SCR *sp;
551 size_t lno, cno;
553 WINDOW *win;
554 win = CLSP(sp) ? CLSP(sp) : stdscr;
555 /* See the comment in cl_cursor. */
556 if (wmove(win, RLNO(sp, lno), RCNO(sp, cno)) == ERR) {
557 msgq(sp, M_ERR, "Error: move: l(%u + %u) c(%u + %u)",
558 lno, sp->roff, cno, sp->coff);
559 return (1);
561 return (0);
565 * cl_refresh --
566 * Refresh the screen.
568 * PUBLIC: int cl_refresh __P((SCR *, int));
571 cl_refresh(sp, repaint)
572 SCR *sp;
573 int repaint;
575 GS *gp;
576 CL_PRIVATE *clp;
577 WINDOW *win;
578 SCR *psp, *tsp;
579 size_t y, x;
581 gp = sp->gp;
582 clp = CLP(sp);
583 win = CLSP(sp) ? CLSP(sp) : stdscr;
586 * If we received a killer signal, we're done, there's no point
587 * in refreshing the screen.
589 if (clp->killersig)
590 return (0);
593 * If repaint is set, the editor is telling us that we don't know
594 * what's on the screen, so we have to repaint from scratch.
596 * If repaint set or the screen layout changed, we need to redraw
597 * any lines separating vertically split screens. If the horizontal
598 * offsets are the same, then the split was vertical, and need to
599 * draw a dividing line.
601 if (repaint || F_ISSET(clp, CL_LAYOUT)) {
602 getyx(stdscr, y, x);
603 for (psp = sp;
604 psp != (void *)&sp->wp->scrq; psp = psp->q.cqe_next)
605 for (tsp = psp->q.cqe_next;
606 tsp != (void *)&sp->wp->scrq;
607 tsp = tsp->q.cqe_next)
608 if (psp->roff == tsp->roff) {
609 if (psp->coff + psp->cols + 1 == tsp->coff)
610 cl_rdiv(psp);
611 else
612 if (tsp->coff + tsp->cols + 1 == psp->coff)
613 cl_rdiv(tsp);
615 (void)wmove(stdscr, y, x);
616 F_CLR(clp, CL_LAYOUT);
620 * In the curses library, doing wrefresh(curscr) is okay, but the
621 * screen flashes when we then apply the refresh() to bring it up
622 * to date. So, use clearok().
624 if (repaint)
625 clearok(curscr, 1);
627 * Only do an actual refresh, when this is the focus window,
628 * i.e. the one holding the cursor. This assumes that refresh
629 * is called for that window after refreshing the others.
630 * This prevents the cursor being drawn in the other windows.
632 return (wnoutrefresh(stdscr) == ERR ||
633 wnoutrefresh(win) == ERR ||
634 (sp == clp->focus && doupdate() == ERR));
638 * cl_rdiv --
639 * Draw a dividing line between two vertically split screens.
641 static void
642 cl_rdiv(sp)
643 SCR *sp;
645 size_t cnt;
647 for (cnt = 0; cnt < sp->rows - 1; ++cnt) {
648 wmove(stdscr, sp->roff + cnt, sp->cols + sp->coff);
649 waddch(stdscr, '|');
654 * cl_rename --
655 * Rename the file.
657 * PUBLIC: int cl_rename __P((SCR *, char *, int));
660 cl_rename(sp, name, on)
661 SCR *sp;
662 char *name;
663 int on;
665 CL_PRIVATE *clp;
666 FILE *pfp;
667 GS *gp;
668 char buf[256], *p;
670 gp = sp->gp;
671 clp = CLP(sp);
673 if (on) {
674 clp->focus = sp;
675 if (!F_ISSET(clp, CL_RENAME_OK))
676 return (0);
679 * XXX
680 * We can only rename windows for xterm.
682 if (strncmp(OG_STR(gp, GO_TERM), "xterm", sizeof("xterm") - 1))
683 return (0);
686 * XXX
687 * Try and figure out the current name of this window. There
688 * are two forms of the xwininfo output I've seen:
690 * Window id: 0x400000d "name"
691 * Window id: 0x140000d (name)
693 #define COMMAND \
694 "expr \"`xwininfo -id $WINDOWID | grep id:`\" : '.* [\"(]\\(.*\\)[\")]'"
696 if (clp->oname == NULL &&
697 (pfp = popen(COMMAND, "r")) != NULL) {
698 if (fgets(buf, sizeof(buf), pfp) != NULL &&
699 (p = strchr(buf, '\n')) != NULL) {
700 *p = '\0';
701 clp->oname = strdup(buf);
703 (void)fclose(pfp);
706 cl_setname(gp, name);
708 F_SET(clp, CL_RENAME);
709 } else
710 if (F_ISSET(clp, CL_RENAME)) {
711 cl_setname(gp, clp->oname);
713 F_CLR(clp, CL_RENAME);
715 return (0);
719 * cl_setname --
720 * Set a X11 icon/window name.
722 * PUBLIC: void cl_setname __P((GS *, char *));
724 void
725 cl_setname(gp, name)
726 GS *gp;
727 char *name;
729 /* X11 xterm escape sequence to rename the icon/window. */
730 #define XTERM_RENAME "\033]0;%s\007"
732 (void)printf(XTERM_RENAME, name == NULL ? OG_STR(gp, GO_TERM) : name);
733 (void)fflush(stdout);
737 * cl_split --
738 * Split a screen.
740 * PUBLIC: int cl_split __P((SCR *, SCR *));
743 cl_split(origp, newp)
744 SCR *origp, *newp;
746 CL_PRIVATE *clp;
748 clp = CLP(origp);
749 F_SET(clp, CL_LAYOUT);
751 if (CLSP(origp))
752 delwin(CLSP(origp));
754 CLSP(origp) = subwin(stdscr, origp->rows, origp->cols,
755 origp->roff, origp->coff);
756 CLSP(newp) = subwin(stdscr, newp->rows, newp->cols,
757 newp->roff, newp->coff);
759 /* origp is the original screen, giving up space to newp. */
760 return (0);
764 * cl_suspend --
765 * Suspend a screen.
767 * PUBLIC: int cl_suspend __P((SCR *, int *));
770 cl_suspend(sp, allowedp)
771 SCR *sp;
772 int *allowedp;
774 struct termios t;
775 CL_PRIVATE *clp;
776 WINDOW *win;
777 GS *gp;
778 size_t y, x;
779 int changed;
781 gp = sp->gp;
782 clp = CLP(sp);
783 win = CLSP(sp) ? CLSP(sp) : stdscr;
784 *allowedp = 1;
787 * The ex implementation of this function isn't needed by screens not
788 * supporting ex commands that require full terminal canonical mode
789 * (e.g. :suspend).
791 * The vi implementation of this function isn't needed by screens not
792 * supporting vi process suspension, i.e. any screen that isn't backed
793 * by a UNIX shell.
795 * Setting allowedp to 0 will cause the editor to reject the command.
797 if (F_ISSET(sp, SC_EX)) {
798 /* Save the terminal settings, and restore the original ones. */
799 if (F_ISSET(clp, CL_STDIN_TTY)) {
800 (void)tcgetattr(STDIN_FILENO, &t);
801 (void)tcsetattr(STDIN_FILENO,
802 TCSASOFT | TCSADRAIN, &clp->orig);
805 /* Stop the process group. */
806 (void)kill(0, SIGTSTP);
808 /* Time passes ... */
810 /* Restore terminal settings. */
811 if (F_ISSET(clp, CL_STDIN_TTY))
812 (void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);
813 return (0);
817 * Move to the lower left-hand corner of the screen.
819 * XXX
820 * Not sure this is necessary in System V implementations, but it
821 * shouldn't hurt.
823 getyx(win, y, x);
824 (void)wmove(win, LINES - 1, 0);
825 (void)wrefresh(win);
828 * Temporarily end the screen. System V introduced a semantic where
829 * endwin() could be restarted. We use it because restarting curses
830 * from scratch often fails in System V. 4BSD curses didn't support
831 * restarting after endwin(), so we have to do what clean up we can
832 * without calling it.
834 /* Save the terminal settings. */
835 (void)tcgetattr(STDIN_FILENO, &t);
837 /* Restore the cursor keys to normal mode. */
838 (void)keypad(stdscr, FALSE);
840 /* Restore the window name. */
841 (void)cl_rename(sp, NULL, 0);
843 #ifdef HAVE_BSD_CURSES
844 (void)cl_attr(sp, SA_ALTERNATE, 0);
845 #else
846 (void)endwin();
847 #endif
849 * XXX
850 * Restore the original terminal settings. This is bad -- the
851 * reset can cause character loss from the tty queue. However,
852 * we can't call endwin() in BSD curses implementations, and too
853 * many System V curses implementations don't get it right.
855 (void)tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &clp->orig);
857 /* Stop the process group. */
858 (void)kill(0, SIGTSTP);
860 /* Time passes ... */
863 * If we received a killer signal, we're done. Leave everything
864 * unchanged. In addition, the terminal has already been reset
865 * correctly, so leave it alone.
867 if (clp->killersig) {
868 F_CLR(clp, CL_SCR_EX_INIT | CL_SCR_VI_INIT);
869 return (0);
872 /* Restore terminal settings. */
873 wrefresh(win); /* Needed on SunOs/Solaris ? */
874 if (F_ISSET(clp, CL_STDIN_TTY))
875 (void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);
877 #ifdef HAVE_BSD_CURSES
878 (void)cl_attr(sp, SA_ALTERNATE, 1);
879 #endif
881 /* Set the window name. */
882 (void)cl_rename(sp, sp->frp->name, 1);
884 /* Put the cursor keys into application mode. */
885 (void)keypad(stdscr, TRUE);
887 /* Refresh and repaint the screen. */
888 (void)wmove(win, y, x);
889 (void)cl_refresh(sp, 1);
891 /* If the screen changed size, set the SIGWINCH bit. */
892 if (cl_ssize(sp, 1, NULL, NULL, &changed))
893 return (1);
894 if (changed)
895 F_SET(CLP(sp), CL_SIGWINCH);
897 return (0);
901 * cl_usage --
902 * Print out the curses usage messages.
904 * PUBLIC: void cl_usage __P((void));
906 void
907 cl_usage()
909 #define USAGE "\
910 usage: ex [-eFRrSsv] [-c command] [-t tag] [-w size] [file ...]\n\
911 usage: vi [-eFlRrSv] [-c command] [-t tag] [-w size] [file ...]\n"
912 (void)fprintf(stderr, "%s", USAGE);
913 #undef USAGE
916 #ifdef DEBUG
918 * gdbrefresh --
919 * Stub routine so can flush out curses screen changes using gdb.
922 gdbrefresh()
924 refresh();
925 return (0); /* XXX Convince gdb to run it. */
927 #endif